Random Text for Objects and Scenery
dwn
02 Feb 2013, 23:27Can anyone help point out the easiest way to implement random text messages when the player looks at a person or object or piece of scenery during a game? So that the description can be a little different if a player looks at something like an object more than once?
I don't want any kind of flags or variables to change, I just want to be able to generate randomized multiple descriptions every time a player looks at an object in the game... Thanks for any help!
I don't want any kind of flags or variables to change, I just want to be able to generate randomized multiple descriptions every time a player looks at an object in the game... Thanks for any help!
HegemonKhan
03 Feb 2013, 03:12http://quest5.net/wiki/GetRandomInt
GetRandomInt ( integer min , integer max )
http://quest5.net/wiki/Switch
switch (any type value) { case (any type value) { script } [ default { script } ] }
---------
example:
Object (male orc) -> Description -> Run A Script
GetRandomInt ( integer min , integer max )
http://quest5.net/wiki/Switch
switch (any type value) { case (any type value) { script } [ default { script } ] }
---------
example:
Object (male orc) -> Description -> Run A Script
result = GetRandomInt (1,3)
switch (result) {
case ("1") {
msg ("He's green")
}
case ("2") {
msg ("He's mean")
}
case ("3") {
msg ("He's hungry")
}
}
dwn
03 Feb 2013, 04:09---------
example:
Object (male orc) -> Description -> Run A Script
Thanks...and maybe I missed this in the tutorial, but where and how do you insert this code into the game to implement it?
example:
Object (male orc) -> Description -> Run A Script
result = GetRandomInt (1,3)
switch (result) {
case ("1") {
msg ("He's green")
}
case ("2") {
msg ("He's mean")
}
case ("3") {
msg ("He's hungry")
}
}
[/quote]Thanks...and maybe I missed this in the tutorial, but where and how do you insert this code into the game to implement it?
HegemonKhan
03 Feb 2013, 04:52there's a toggle button for the GUI and Code View modes at the top of the screen, looks like a piece of notepaper, between the play and ? (help) buttons.
Examples:
via the GUI mode:
Object (player) -> Setup (Tab) -> Description -> [Run Script] ->
Add New Script -> Variables -> Set A Variable or Attribute -> Set Variable (result) = [random number] between [number] (1) and [number] (3)
Add New Script -> Scripts -> Switch... -> (result)
-> Cases -> Add -> "1"
->-> Print [message] ("You are the hero")
-> Cases -> Add -> "2"
->-> Print [message] ("You are the best")
-> Cases -> Add -> "3"
->-> Print [message] ("You are the champ")
Object (room) -> Objects (Tab) -> Add -> (name) orc (and) (parent) room (it should already be set to room)
Object (orc) -> Setup (Tab) -> Description -> [Run Script] ->
Add New Script -> Variables -> Set A Variable or Attribute -> Set Variable (result) = [random number] between [number] (1) and [number] (3)
Add New Script -> Scripts -> Switch... -> (result)
-> Cases -> Add -> "1"
->-> Print [message] ("He's green")
-> Cases -> Add -> "2"
->-> Print [message] ("He's mean")
-> Cases -> Add -> "3"
->-> Print [message] ("He's hungry")
via the Code View mode:
-------------------
you can copy and paste this code, and try it out yourself. simply type in: look at player/orc (or use the display pane's button or text's hyperlink choice for the orc)
----------------
obviously, adjust the code as you want to do so for each object that you want your random descriptions for.
------------
let me know if you're still confused or need help!
Examples:
via the GUI mode:
Object (player) -> Setup (Tab) -> Description -> [Run Script] ->
Add New Script -> Variables -> Set A Variable or Attribute -> Set Variable (result) = [random number] between [number] (1) and [number] (3)
Add New Script -> Scripts -> Switch... -> (result)
-> Cases -> Add -> "1"
->-> Print [message] ("You are the hero")
-> Cases -> Add -> "2"
->-> Print [message] ("You are the best")
-> Cases -> Add -> "3"
->-> Print [message] ("You are the champ")
Object (room) -> Objects (Tab) -> Add -> (name) orc (and) (parent) room (it should already be set to room)
Object (orc) -> Setup (Tab) -> Description -> [Run Script] ->
Add New Script -> Variables -> Set A Variable or Attribute -> Set Variable (result) = [random number] between [number] (1) and [number] (3)
Add New Script -> Scripts -> Switch... -> (result)
-> Cases -> Add -> "1"
->-> Print [message] ("He's green")
-> Cases -> Add -> "2"
->-> Print [message] ("He's mean")
-> Cases -> Add -> "3"
->-> Print [message] ("He's hungry")
via the Code View mode:
<asl version="530">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>d83ba5bb-2e3c-4f31-80c9-3e88a2dc082c</gameid>
<version>1.0</version>
<pov type="object">player</pov>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="defaultplayer" />
<inherit name="editor_player" />
<look type="script">
result = GetRandomInt(1,3)
switch (result) {
case ("1") {
msg ("You are the hero")
}
case ("2") {
msg ("You are the best")
}
case ("3") {
msg ("You are the champ")
}
}
</look>
</object>
<object name="orc">
<look type="script">
result = GetRandomInt (1,3)
switch (result) {
case ("1") {
msg ("He's green")
}
case ("2") {
msg ("He's mean")
}
case ("3") {
msg ("He's hungry")
}
}
</look>
</object>
</object>
</asl>
-------------------
you can copy and paste this code, and try it out yourself. simply type in: look at player/orc (or use the display pane's button or text's hyperlink choice for the orc)
----------------
obviously, adjust the code as you want to do so for each object that you want your random descriptions for.
------------
let me know if you're still confused or need help!
dwn
03 Feb 2013, 05:33Thanks, I was a little unsure exactly where to place the code snippet, but seems to work! Onto the next one...
HegemonKhan
03 Feb 2013, 05:39description = the look script
so (if you're using the Code View mode) simply place the look script under~in that specific object's script block:
so (if you're using the Code View mode) simply place the look script under~in that specific object's script block:
<object name="room">
<object name="player">
(look script)
</object>
<object name="orc">
(look script)
</object>
</object>
<object name="room_2">
(look script for the room_2)
<object name="troll">
(look script for the troll)
<object name="club">
(look script for the club)
</object>
</object>
</object>
Ceresbane
03 Feb 2013, 16:20In regards to this how do you define what an does If you interact with them besides looking?
e.g. look at automatically uses the description.
But how do you define how a character talks to you besides "has nothing to say"?
e.g. look at automatically uses the description.
But how do you define how a character talks to you besides "has nothing to say"?
HegemonKhan
04 Feb 2013, 02:58simply create the same~similar script code for whatever verb~command you want (such as ' talk to '), or you can create your own verbs~commands too, and apply the same~similar script code to them.
here's on using a talk command:
http://quest5.net/wiki/Custom_commands
(scroll to the bottom, after the weighing stuff, called "Another Example")
here's about the ask/tell verbs:
http://quest5.net/wiki/More_things_to_do_with_objects
here's about conversations:
http://quest5.net/wiki/Conversations
here's about conversations 2:
http://quest5.net/wiki/Dynamic_Menus_for_Conversations
here's about random default answers:
http://quest5.net/wiki/Random_default_answers
more about ask/tell verb:
http://quest5.net/wiki/Hs-asktell
-----------
if you need any help or a detailed explanation, or confused, let me know, and I'll help out.
here's on using a talk command:
http://quest5.net/wiki/Custom_commands
(scroll to the bottom, after the weighing stuff, called "Another Example")
here's about the ask/tell verbs:
http://quest5.net/wiki/More_things_to_do_with_objects
here's about conversations:
http://quest5.net/wiki/Conversations
here's about conversations 2:
http://quest5.net/wiki/Dynamic_Menus_for_Conversations
here's about random default answers:
http://quest5.net/wiki/Random_default_answers
more about ask/tell verb:
http://quest5.net/wiki/Hs-asktell
-----------
if you need any help or a detailed explanation, or confused, let me know, and I'll help out.
sgreig
06 Feb 2013, 08:40Another method you can use it to create a string list with all of the different descriptions you want to use for an object, and then randomly select one from the list. It's a bit more concise than using case switches, but it accomplishes the same thing. I'm doing this off the top of my head, so apologies if there are any mistakes.
You'd probably want to put this in the game start script so the lists is created when the game is started. I'm using a book as the example here.
That code creates the list and then adds the various descriptions to the list. The list items are zero-indexed (meaning the first item is numbered 0, the second 1, etc.). The description can be pulled by StringListItem(game.bookDesc, 0) for example. So, on the book object, you'd change the description to a script and do the following:
What this does is set the message command to display a random string from the list game.bookDesc. By making the list part of the game object, it can be called from anywhere else in the game. The reason the "-1" is at the end is because lists are zero-indexed, this way the random number will be 0 - 2 instead of 1-3. I don't think you can specify a 0 as the starting integer for the GetRandomInt function. The only thing you need to keep in mind with this is to change the second value of GetRandomInt to the number of items in the string list, so if you have 5 descriptions, it would be GetRandomInt(1,5) instead. Does that make any sense? lol
Anyway, I don't want to confuse things any more than they probably are, but my game Sleuth makes extensive use of randomized elements and I found this to be the sanest way to implement them with the minimum amount of typing.
EDIT: I forgot to mention, as an alternative to creating the list in the game start script, you could just create the string list in the attributes tab of the game object and add the different strings there as well. That is probably the easiest way to set up the lists now that I think of it.
You'd probably want to put this in the game start script so the lists is created when the game is started. I'm using a book as the example here.
game.bookDesc = newStringList()
list add (game.bookDesc, "A dusty old tome.")
list add (game.bookDesc, "It's a weathered volume.")
list add (game.bookDesc, "A very old book with that familiar musty book smell.")
That code creates the list and then adds the various descriptions to the list. The list items are zero-indexed (meaning the first item is numbered 0, the second 1, etc.). The description can be pulled by StringListItem(game.bookDesc, 0) for example. So, on the book object, you'd change the description to a script and do the following:
msg(StringListItem(game.bookDesc, GetRandomInt(1,3) - 1))
What this does is set the message command to display a random string from the list game.bookDesc. By making the list part of the game object, it can be called from anywhere else in the game. The reason the "-1" is at the end is because lists are zero-indexed, this way the random number will be 0 - 2 instead of 1-3. I don't think you can specify a 0 as the starting integer for the GetRandomInt function. The only thing you need to keep in mind with this is to change the second value of GetRandomInt to the number of items in the string list, so if you have 5 descriptions, it would be GetRandomInt(1,5) instead. Does that make any sense? lol
Anyway, I don't want to confuse things any more than they probably are, but my game Sleuth makes extensive use of randomized elements and I found this to be the sanest way to implement them with the minimum amount of typing.

EDIT: I forgot to mention, as an alternative to creating the list in the game start script, you could just create the string list in the attributes tab of the game object and add the different strings there as well. That is probably the easiest way to set up the lists now that I think of it.

dwn
07 Feb 2013, 02:28sgreig wrote:Another method you can use it to create a string list with all of the different descriptions you want to use for an object, and then randomly select one from the list. It's a bit more concise than using case switches, but it accomplishes the same thing. I'm doing this off the top of my head, so apologies if there are any mistakes.
EDIT: I forgot to mention, as an alternative to creating the list in the game start script, you could just create the string list in the attributes tab of the game object and add the different strings there as well. That is probably the easiest way to set up the lists now that I think of it.
Thank you, that will be very useful for a lot of things I have in mind!