Remove Integer from list
michaelsahn
26 Feb 2014, 05:15Hello -
I am using GetRandomInt to randomly select an outcome. I'd like to remove that integer once it's been selected. How can I do this? Thanks.
I am using GetRandomInt to randomly select an outcome. I'd like to remove that integer once it's been selected. How can I do this? Thanks.
outcome = GetRandomInt(1,2)
if (outcome = 1) {
msg ("She says nothing.")
}
else if (outcome = 2) {
msg ("She is crying. She tells Emily she saw a bird fall out of its nest but was too frightening to help it.")
MakeObjectVisible (nest)
MakeObjectVisible (robin)
}
Liam315
26 Feb 2014, 05:54You don't have to do anything, it is not stored anywhere permanently and should have no effect on future scripts that are run.
To explain in more detail, there are 2 types of variables, local variables and global variables.
- A global variable is something that exists permanently in the game, e.g. an attribute of an object is a global variable. An object called "brick" might have an attribute called "weight" set to a value of 20. A script that has the expression brick.weight will always be 20 no matter where you insert it in the game.
- A local variable is something that only exists temporarily in the current script that is being run. In your case, you've set the variable "outcome" to be either a 1 or a 2. The later parts of your script use the variable "outcome" to describe that number, but if you were to reference "outcome" in another part of the game, Quest wouldn't know what you were talking about (unless you set another variable called outcome in that script).
Even though you don't need to do this for the example you gave, all you need to do to wipe a variable is to set it to null, i.e.
outcome = null
or
brick.takemsg = null
etc.
Furthermore, if your concern is about the player repeating the action that causes the script to run, because outcome is set to GetRandomInt at the beginning of the script, the 1 or 2 will be freshly randomized every time the player performs that action. So again, there is nothing extra that you need to add.
To explain in more detail, there are 2 types of variables, local variables and global variables.
- A global variable is something that exists permanently in the game, e.g. an attribute of an object is a global variable. An object called "brick" might have an attribute called "weight" set to a value of 20. A script that has the expression brick.weight will always be 20 no matter where you insert it in the game.
- A local variable is something that only exists temporarily in the current script that is being run. In your case, you've set the variable "outcome" to be either a 1 or a 2. The later parts of your script use the variable "outcome" to describe that number, but if you were to reference "outcome" in another part of the game, Quest wouldn't know what you were talking about (unless you set another variable called outcome in that script).
Even though you don't need to do this for the example you gave, all you need to do to wipe a variable is to set it to null, i.e.
outcome = null
or
brick.takemsg = null
etc.
Furthermore, if your concern is about the player repeating the action that causes the script to run, because outcome is set to GetRandomInt at the beginning of the script, the 1 or 2 will be freshly randomized every time the player performs that action. So again, there is nothing extra that you need to add.
HegemonKhan
26 Feb 2014, 07:25aside from Liam's post, if you have a global list (ie: Object.List_Attribute), then you can add and remove items from that list.
here's an example of it, using my travel coding:
(it is a bit complicated for a new person to coding, however)
Specifically:
and here's my entire "game" (game testing) code:
Explore (Command~Function):
discovery of the areas of the game events (this lets you then travel~goto those areas)
however, I need to remove these "area discovery events" as you get them from "exploring", obviously. So as you get them, I remove them from the list, so they're not selected again the next time you "explore".
Travel (Command~Function):
once you discover an area (as an event from "exploring"), you can now travel to and from that newly discovered area.
--------------
if you need me to explain how it works, please let me know, and I'll help explain it, until it makes sense to you!
here's an example of it, using my travel coding:
(it is a bit complicated for a new person to coding, however)
Specifically:
<function name="explore_function"><![CDATA[
switch (game.pov.parent) {
case (homeland) {
result_1 = ListCount (data_object.homeland_events_string_list) - 1
if (result_1 >= 0) {
result_2 = StringListItem (data_object.homeland_events_string_list,GetRandomInt(0,result_1))
invoke (ScriptDictionaryItem (data_object.homeland_events_script_dictionary,result_2))
on ready {
foreach (item_x, split ("grassland_discovery;plains_discovery;desert_discovery;tundra_discovery;swampland_discovery;forest_discovery;mountains_discovery;hills_discovery;wasteland_discovery;coastland_discovery",";")) {
if (result_2 = item_x) {
list remove (data_object.homeland_events_string_list, result_2)
}
}
}
} else {
msg ("There seemingly is nothing left to explore in this area.")
}
}
}
]]></function>
and here's my entire "game" (game testing) code:
<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>eef801a1-4e6b-4b0a-bdbf-8f3ecfa8389c</gameid>
<version>1.0</version>
<firstpublished>2013</firstpublished>
<turns type="int">0</turns>
<statusattributes type="simplestringdictionary">turns=</statusattributes>
<start type="script">
msg ("Important Note:")
msg ("Type in: help")
</start>
</game>
<object name="homeland">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
</object>
<object name="grassland">
<inherit name="editor_room" />
</object>
<object name="plains">
<inherit name="editor_room" />
</object>
<object name="desert">
<inherit name="editor_room" />
</object>
<object name="tundra">
<inherit name="editor_room" />
</object>
<object name="swampland">
<inherit name="editor_room" />
</object>
<object name="mountains">
<inherit name="editor_room" />
</object>
<object name="forest">
<inherit name="editor_room" />
</object>
<object name="wasteland">
<inherit name="editor_room" />
</object>
<object name="coastland">
<inherit name="editor_room" />
</object>
<object name="hills">
<inherit name="editor_room" />
</object>
<command name="help_command">
<pattern>help</pattern>
<script>
help_function
</script>
</command>
<command name="explore_command">
<pattern>explore</pattern>
<script>
explore_function
</script>
</command>
<command name="travel_command">
<pattern>travel</pattern>
<script>
travel_function
</script>
</command>
<object name="data_object">
<inherit name="editor_object" />
<travel_string_list type="simplestringlist">homeland</travel_string_list>
<homeland_events_string_list type="simplestringlist">grassland_discovery;plains_discovery;desert_discovery;tundra_discovery;swampland_discovery;forest_discovery;mountains_discovery;hills_discovery;wasteland_discovery;coastland_discovery</homeland_events_string_list>
<homeland_events_script_dictionary type="scriptdictionary">
<item key="grassland_discovery">
list add (data_object.travel_string_list, "grassland")
msg ("You've discovered the grassland! Now, you can travel to the grassland and explore it!")
</item>
<item key="plains_discovery">
list add (data_object.travel_string_list, "plains")
msg ("You've discovered the plains! Now, you can travel to the plains and explore it!")
</item>
<item key="desert_discovery">
list add (data_object.travel_string_list, "desert")
msg ("You've discovered the desert! Now, you can travel to the desert and explore it!")
</item>
<item key="tundra_discovery">
list add (data_object.travel_string_list, "tundra")
msg ("You've discovered the tundra! Now, you can travel to the tundra and explore it!")
</item>
<item key="swampland_discovery">
list add (data_object.travel_string_list, "swampland")
msg ("You've discovered the swampland! Now, you can travel to the swampland and explore it!")
</item>
<item key="forest_discovery">
list add (data_object.travel_string_list, "forest")
msg ("You've discovered the forest! Now, you can travel to the forest and explore it!")
</item>
<item key="mountains_discovery">
list add (data_object.travel_string_list, "mountains")
msg ("You've discovered the mountains! Now, you can travel to the mountains and explore it!")
</item>
<item key="hills_discovery">
list add (data_object.travel_string_list, "hills")
msg ("You've discovered the hills! Now, you can travel to the hills and explore it!")
</item>
<item key="wasteland_discovery">
list add (data_object.travel_string_list, "wasteland")
msg ("You've discovered the wasteland! Now, you can travel to the wasteland and explore it!")
</item>
<item key="coastland_discovery">
list add (data_object.travel_string_list, "coastland")
msg ("You've discovered the coastland! Now, you can travel to the coastland and explore it!")
</item>
</homeland_events_script_dictionary>
</object>
<turnscript name="global_turnscript">
<enabled />
<script>
game.turns = game.turns + 1
</script>
</turnscript>
<function name="help_function">
msg ("Type 'explore' to explore your area.")
msg ("Type 'travel' to travel to different areas.")
</function>
<function name="explore_function"><![CDATA[
switch (game.pov.parent) {
case (homeland) {
result_1 = ListCount (data_object.homeland_events_string_list) - 1
if (result_1 >= 0) {
result_2 = StringListItem (data_object.homeland_events_string_list,GetRandomInt(0,result_1))
invoke (ScriptDictionaryItem (data_object.homeland_events_script_dictionary,result_2))
on ready {
foreach (item_x, split ("grassland_discovery;plains_discovery;desert_discovery;tundra_discovery;swampland_discovery;forest_discovery;mountains_discovery;hills_discovery;wasteland_discovery;coastland_discovery",";")) {
if (result_2 = item_x) {
list remove (data_object.homeland_events_string_list, result_2)
}
}
}
} else {
msg ("There seemingly is nothing left to explore in this area.")
}
}
}
]]></function>
<function name="travel_function">
show menu ("Where do you wish to travel?",data_object.travel_string_list,false) {
if (not game.pov.parent = GetObject (result)) {
game.pov.parent = GetObject (result)
} else {
msg ("You are already at this area.")
ask ("Try again?") {
if (result=true) {
travel_function
} else {
msg ("You realize that you need to discover a new area to travel to first, before you can travel to that place.")
}
}
}
}
</function>
</asl>
Explore (Command~Function):
discovery of the areas of the game events (this lets you then travel~goto those areas)
however, I need to remove these "area discovery events" as you get them from "exploring", obviously. So as you get them, I remove them from the list, so they're not selected again the next time you "explore".
Travel (Command~Function):
once you discover an area (as an event from "exploring"), you can now travel to and from that newly discovered area.
--------------
if you need me to explain how it works, please let me know, and I'll help explain it, until it makes sense to you!

michaelsahn
26 Feb 2014, 15:08Thank you both for your responses. I should have said what I'm trying to accomplish in code:
- I have characters in rooms for the player to speak to.
- When the player uses verb "speak to" with a character, the code randomly prints a response.
- I'd like it so that, when the player encounters the character again, and the code randomly selects a response, it does not select a previously used response.
Therefore, how do I randomly select from a list without having the code repeat a selection?
Thanks -
Mike
- I have characters in rooms for the player to speak to.
- When the player uses verb "speak to" with a character, the code randomly prints a response.
- I'd like it so that, when the player encounters the character again, and the code randomly selects a response, it does not select a previously used response.
Therefore, how do I randomly select from a list without having the code repeat a selection?
Thanks -
Mike
HegemonKhan
26 Feb 2014, 18:35that would be my travel code, and I thus presume you need help with it, hehe (as it is complicated for new people to coding).
-----------------------------
useful links:
1. http://quest5.net/wiki/Category:All_Fun ... t_Commands (page 1, range: A-S)
2. http://quest5.net/w/index.php?title=Cat ... h#mw-pages (page 2, range: S-Z)
3. http://quest5.net/wiki/Using_Lists
4. http://quest5.net/wiki/Using_Dictionaries
--------------
my step by step guide:
1. first, let's create (add) a "data storage object", so we don't clutter up the "game" object with global attributes:
(and it makes it easier, and more organized too, for further expansion of ~ an actual game worth of content and not just my example test game limited amount of content, lol, for example, dialogue~topics)
(if you want topics specific to only each individual characters~NPCs, then instead, just put the below stuff~Attributes~Scripts within that "character~NPC" Object's Attributes and Verbs)
In the GUI~Editor: just make (add) an (Type: Object Object; Non-Room Object; Non-Player Object) Object that is NOT inside of a room (Room Object), a Player Object, or another Object Object.
in Code:
<object name="global_data_object">
-> <inherit name="editor_object" />
</object>
2. create (add) your String List Attribute:
this is the dynamic list, that we'll be adding~removing topics to~from, to set what is available for random selection at any given time.
(we can start with it being blank too, as a variation)
In the GUI~Editor: "global_data_object" Object -> Attributes (Tab) -> Attributes -> Add ->
Attribute Name: topic_string_list
Attribute Type: String List
Attribute Value: (add in your topic keywords, ie: dragon; sword; princess)
In Scripting: Run as script -> Add a script -> Variables -> Set a variable or attribute -> (see below, the code scripting, for what to type in)
In Code:
<object name="global_data_object">
-> <inherit name="editor_object" />
-> <attr name="topic_string_list" type="simplestringlist">dragon;sword;princess</attr>
</object>
In Scripting: global_data_object.topic_string_list = split ("dragon;sword;princess",";")
In Scripting: StringListItem (global_data_object.topic_string_list, your keyword's counting index number in the list)
Lists start from 0, from left to right: (0) dragon, (1) sword, and (2) princess
("result" can be changed to what you want to call it, such as for example: "topic")
result = StringListItem (global_data_object.topic_string_list, 1)
input: 1
output~returns: sword
result = sword
result = StringListItem (global_data_object.topic_string_list, 2)
input: 2
output~returns: princess
result = princess
result = StringListItem (global_data_object.topic_string_list, 0)
input: 0
output~returns: dragon
result = dragon
result = StringListItem (global_data_object.topic_string_list, GetRandomInt (0,2))
input: (0-2)
output~returns: (dragon, sword, or princess)
result = (dragon, sword, or princess)
result = StringListItem (global_data_object.topic_string_list, GetRandomInt (0, ListCount (global_data_object.topic_string_list) - 1))
input: (0-whatever is the current size of the list ~ dynamic, and thus useful for us when we add~remove items from the list)
output~returns: (depends what items the list currently contains)
result = (depends what items the list currently contains)
3. create (add) a Script Dictionary Attribute:
In the GUI~Editor:
"global_data_object" Object -> Attributes (Tab) -> Attributes -> Add ->
Attribute Name: topic_script_dictionary
Attribute Type: Script Dictionary
Key Items: dragon, sword, and princess
Values (Scripts): (see below)
dragon:
run as script -> add a script -> (for example) -> output -> print a message -> MESSAGE -> the evil dragon has kidnapped the princess, you must save her from the evil dragon!
sword:
(same as above... blah blah blah)
princess:
(same as above... blah blah blah)
In code:
4. concept of what we're doing with the string list and script dictionary:
the script dictionary as can be seen, is what our topics are:
if dragon, then msg: blah blah blah
if sword, then msg: blah blah blah
if princess, then msg: blah blah blah
our string list is used to determine what topics are currently available for the script dictionary:
if string list (dragon,sword,princess), and if randomness selects (x=dragon,sword,or princess), then script dictionary (x=dragon,sword, or princess) msg: blah blah blah
if string list (dragon,sword), and if randomness selects (x=dragon or sword), then script dictionary (x=dragon or sword) msg: blah blah blah
you get the idea... I hope
so... conceptually:
if (choosen string list item~topic = script dictionary key~word item), then do that script dictionary item's msg script: blah
if (StringList: dragon = ScriptDictionary: dragon), then do ScriptDictionary: dragon 's script, ie msg: blah blah blah
if (dragon = dragon), then do ScriptDictionary's dragon's script, ie msg: blah blah blah
"match comparisons" (if string_1 = string_2 ~ if dragon = dragon) are a huge part of the tactic~logic~technique of doing things in code
5. which gets us to the complicated part, the removal (or the addition of ~ which I'm not going to cover right now) of topics to select from:
let's say we've got some topics that we want to remove (one-time topic events) and some topics that we don't want to remove (repeatable topic events)
thus we must craft a function correctly, to deal with this complexity
-----------------------------
useful links:
1. http://quest5.net/wiki/Category:All_Fun ... t_Commands (page 1, range: A-S)
2. http://quest5.net/w/index.php?title=Cat ... h#mw-pages (page 2, range: S-Z)
3. http://quest5.net/wiki/Using_Lists
4. http://quest5.net/wiki/Using_Dictionaries
--------------
my step by step guide:
1. first, let's create (add) a "data storage object", so we don't clutter up the "game" object with global attributes:
(and it makes it easier, and more organized too, for further expansion of ~ an actual game worth of content and not just my example test game limited amount of content, lol, for example, dialogue~topics)
(if you want topics specific to only each individual characters~NPCs, then instead, just put the below stuff~Attributes~Scripts within that "character~NPC" Object's Attributes and Verbs)
In the GUI~Editor: just make (add) an (Type: Object Object; Non-Room Object; Non-Player Object) Object that is NOT inside of a room (Room Object), a Player Object, or another Object Object.
in Code:
<object name="global_data_object">
-> <inherit name="editor_object" />
</object>
2. create (add) your String List Attribute:
this is the dynamic list, that we'll be adding~removing topics to~from, to set what is available for random selection at any given time.
(we can start with it being blank too, as a variation)
In the GUI~Editor: "global_data_object" Object -> Attributes (Tab) -> Attributes -> Add ->
Attribute Name: topic_string_list
Attribute Type: String List
Attribute Value: (add in your topic keywords, ie: dragon; sword; princess)
In Scripting: Run as script -> Add a script -> Variables -> Set a variable or attribute -> (see below, the code scripting, for what to type in)
In Code:
<object name="global_data_object">
-> <inherit name="editor_object" />
-> <attr name="topic_string_list" type="simplestringlist">dragon;sword;princess</attr>
</object>
In Scripting: global_data_object.topic_string_list = split ("dragon;sword;princess",";")
In Scripting: StringListItem (global_data_object.topic_string_list, your keyword's counting index number in the list)
Lists start from 0, from left to right: (0) dragon, (1) sword, and (2) princess
("result" can be changed to what you want to call it, such as for example: "topic")
result = StringListItem (global_data_object.topic_string_list, 1)
input: 1
output~returns: sword
result = sword
result = StringListItem (global_data_object.topic_string_list, 2)
input: 2
output~returns: princess
result = princess
result = StringListItem (global_data_object.topic_string_list, 0)
input: 0
output~returns: dragon
result = dragon
result = StringListItem (global_data_object.topic_string_list, GetRandomInt (0,2))
input: (0-2)
output~returns: (dragon, sword, or princess)
result = (dragon, sword, or princess)
result = StringListItem (global_data_object.topic_string_list, GetRandomInt (0, ListCount (global_data_object.topic_string_list) - 1))
input: (0-whatever is the current size of the list ~ dynamic, and thus useful for us when we add~remove items from the list)
output~returns: (depends what items the list currently contains)
result = (depends what items the list currently contains)
3. create (add) a Script Dictionary Attribute:
In the GUI~Editor:
"global_data_object" Object -> Attributes (Tab) -> Attributes -> Add ->
Attribute Name: topic_script_dictionary
Attribute Type: Script Dictionary
Key Items: dragon, sword, and princess
Values (Scripts): (see below)
dragon:
run as script -> add a script -> (for example) -> output -> print a message -> MESSAGE -> the evil dragon has kidnapped the princess, you must save her from the evil dragon!
sword:
(same as above... blah blah blah)
princess:
(same as above... blah blah blah)
In code:
<object name="global_data_object">
<inherit name="editor_object" />
<attr name="topic_string_list" type="simplestringlist">dragon;sword;princess</attr>
<attr name="topic_script_dictionary type="scriptdictionary">
<item key="dragon">
msg ("blah blah blah")
</item>
<item key="sword">
msg ("blah blah blah")
</item>
<item key="princess">
msg ("blah blah blah")
</item>
</attr>
</object>
4. concept of what we're doing with the string list and script dictionary:
the script dictionary as can be seen, is what our topics are:
if dragon, then msg: blah blah blah
if sword, then msg: blah blah blah
if princess, then msg: blah blah blah
our string list is used to determine what topics are currently available for the script dictionary:
if string list (dragon,sword,princess), and if randomness selects (x=dragon,sword,or princess), then script dictionary (x=dragon,sword, or princess) msg: blah blah blah
if string list (dragon,sword), and if randomness selects (x=dragon or sword), then script dictionary (x=dragon or sword) msg: blah blah blah
you get the idea... I hope
so... conceptually:
if (choosen string list item~topic = script dictionary key~word item), then do that script dictionary item's msg script: blah
if (StringList: dragon = ScriptDictionary: dragon), then do ScriptDictionary: dragon 's script, ie msg: blah blah blah
if (dragon = dragon), then do ScriptDictionary's dragon's script, ie msg: blah blah blah
"match comparisons" (if string_1 = string_2 ~ if dragon = dragon) are a huge part of the tactic~logic~technique of doing things in code
5. which gets us to the complicated part, the removal (or the addition of ~ which I'm not going to cover right now) of topics to select from:
let's say we've got some topics that we want to remove (one-time topic events) and some topics that we don't want to remove (repeatable topic events)
thus we must craft a function correctly, to deal with this complexity
Our Function (slightly more complex), and~or Direct Verb (a custom one, so we don't mess up the built-in Verbs, let's call our custom Verb, for example, "chat", lol) Scripting (simplier: just put the below code as the script block for your Verb) of, let's say for example, the Object "wise_owl_npc_your_helpful_guide_through_this_game" (lol):
// we need to do this, to check if there's still topic choices in our string list:
result_1 = ListCount (global_data_object.topic_string_list) - 1
if (result_1 >= 0) {
// we need to do this, to get the current string list size, to get the random choice from that current selection of list choices:
result_2 = StringListItem (global_data_object.topic_string_list,GetRandomInt(0,result_1))
// we cause the the script to run for the choosen topic:
invoke (ScriptDictionaryItem (global_data_object.topic_script_dictionary,result_2))
// and now the beginning of the removal of topics proncess:
on ready {
// we create a list (split) of the topics that can be removed (the one time only topic events), AND we go through each of them (foreach), seeing if they match up with the topic that was randomly selected and run (if), and if they do match up, then we remove the topic from the String List (list remove), as it has already been run, and we don't want it to be selected and run again:
// let's say that we want only "dragon" and "princess" to be one time only topic events, while "sword" is a repeatable topic event, for this example:
foreach (item_x, split ("dragon;princess",";")) {
if (result_2 = item_x) {
list remove (global_data_object.topic_string_list, result_2)
}
}
}
}

jaynabonne
26 Feb 2014, 20:29Here's a simple bit of code that does (I hope) what you want. You didn't say what you wanted to happen when all the strings were exhausted, so I added a small amount of logic to spit out a default message.
It's also attached as a file. The heart of it is this:
It selects a random string from the list and then removes the string from the list. The list is attached to the character in question. I assume each character will have its own response. Straightforward, I hope!
<!--Saved by Quest 5.4.4873.16527-->
<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="RandomSpeaktoTest">
<gameid>14736beb-f775-4ecd-b503-5f46568e0eee</gameid>
<version>1.0</version>
<firstpublished>2014</firstpublished>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<object name="Chatty">
<inherit name="editor_object" />
<inherit name="male" />
<speak type="script">
count = ListCount(this.responses)
if (count = 0) {
s = "I have nothing left to say."
} else {
s = StringListItem(this.responses, GetRandomInt(0, count-1))
list remove(this.responses, s)
}
msg(s)
</speak>
<responses type="stringlist">
<value>I can't even remember the last time I saw someone.,</value>
<value>What can I do for you?</value>
<value>They say it's supposed to rain later. Be sure to take your umbrella,</value>
<value>Be careful what you say. Remember - the walls have teeth.</value>
<value>Argue for your limitations and, sure enough, they're yours.</value>
</responses>
</object>
</object>
</asl>
It's also attached as a file. The heart of it is this:
count = ListCount(this.responses)
if (count = 0) {
s = "I have nothing left to say."
} else {
s = StringListItem(this.responses, GetRandomInt(0, count-1))
list remove(this.responses, s)
}
msg(s)
It selects a random string from the list and then removes the string from the list. The list is attached to the character in question. I assume each character will have its own response. Straightforward, I hope!

HegemonKhan
26 Feb 2014, 20:45I had a lingering bug in my code, and I think thanks to your post Jayna that I found~realized it (finally at long last, lol):
result_1 = ListCount (global_data_object.topic_string_list) - 1
if (result_1 >= 0) {
while, when you're getting (returning) a string list item by it's index, using "GetRandomInt", you need the "ListCount -1" for it's max range value, otherwise, you do NOT want the "-1" when using "ListCount", is this correct ???
-----------------------
HK Edit:
I think I've was confused by a list's index range (0-X) "labelization~defining" ~VS~ simply the actual # of items within a list ("ListCount"), in regards to when I do the "-1", at least I think this is what is causing the lingering bug in my code, anyways, thanks to your post just now.
result_1 = ListCount (global_data_object.topic_string_list) - 1
if (result_1 >= 0) {
while, when you're getting (returning) a string list item by it's index, using "GetRandomInt", you need the "ListCount -1" for it's max range value, otherwise, you do NOT want the "-1" when using "ListCount", is this correct ???
-----------------------
HK Edit:
I think I've was confused by a list's index range (0-X) "labelization~defining" ~VS~ simply the actual # of items within a list ("ListCount"), in regards to when I do the "-1", at least I think this is what is causing the lingering bug in my code, anyways, thanks to your post just now.

jaynabonne
26 Feb 2014, 20:52List indices are 0-based, for any sort of list. So if you have 5 items in the list, then you can use indices 0-4.
(I'm not sure what you mean by "otherwise" - you basically use what the code requirements are. It could be +100 if that's what the rest of the code needs.)
(I'm not sure what you mean by "otherwise" - you basically use what the code requirements are. It could be +100 if that's what the rest of the code needs.)
HegemonKhan
26 Feb 2014, 20:56my "otherwise" means when not doing a return function for the string list item, if this makes any more sense... not sure how to say~explain what I want to say~explain, argh... lol.
I know the syntax or the element settings~options of the functions~scripts, I'm not refering to this with my "otherwise"
I know the syntax or the element settings~options of the functions~scripts, I'm not refering to this with my "otherwise"

jaynabonne
26 Feb 2014, 20:59I think I knew what you meant - you were asking if you wouldn't use the -1 if you weren't using a string list. My point was, if you're not using a (string) list, then it's not possible to say whether you use -1 or not or +100 or *50. It depends on what you're trying to do, why you're getting a random number. Hence my "not sure". Without context, it's impossible to say.

jaynabonne
26 Feb 2014, 21:06A note: Quest is not consistent. Lists are 0-based, but strings are 1-based (e.g. if you use Mid to extract a sub-string, indices start at 1). Sadly, you have to be careful when you use them. When I wrote the above code, I got it wrong the first time, since I couldn't remember. So I wrote the code and watched it fail, then fixed it. 

HegemonKhan
26 Feb 2014, 21:07jay wrote:I think I knew what you meant - you were asking if you wouldn't use the -1 if you weren't using a string list. My point was, if you're not using a (string) list, then it's not possible to say whether you use -1 or not or +100 or *50. It depends on what you're trying to do, why you're getting a random number. Hence my "not sure". Without context, it's impossible to say.
oh, I wasn't even aware of this application that you may want to have within your code~game, laughs. I think I now understand what you're talking about, hehe.
-----
my lingering bug was that it'd think I have no more items (ie: < 0), so I was blocked off from acting upon the last remaining item (upon removing, whittling down~away, the rest of the items) in my travel coding, and couldn't figure out why this was happening.
I think this is due to the difference of the "ListCount" (1 through X) vs the list index ordering~defining~"labelization" (0 through X). I was wrongly putting the "-1" in, where I shouldn't have, confusing with it's required placement (for what it was needed for in my code) of "StringListItem (StringList, GetRandomInt (0, ListCount (StringList) - 1))".
----------
I knew~know that "list indexes" are (0 through X) and "ListCounts" are (1 through X), but I was messing up the application of when~where to use the "-1" (and with what: list indexes vs list counts), and when~where not to do so, at least I think this is my problem from your post, anyways, with my travel code, lol.

jaynabonne
26 Feb 2014, 21:15Actually, the code looks ok. It is a bit awkward to do the -1 where you have it, so it would make sense to move it. But then be sure you change the ">=0" to just ">0".
This:
is equivalent to this:
But I think the latter makes more sense, since "x" is the number of items in the list, which is a reasonable concept - vs. "x" being the number of items - 1, which is a bit weird as a concept. (And I'd rename "x" - or your "result_1" - to be something more friendly, like "count", which is why doing the -1 up front is weird ("count_minus_one"?). The better you can name your variables, the easier it will be for someone to understand your code.)
This:
x = ListCount(list)-1
if (x>=0) {
item = ListItem(list, GetRandomInt(0, x))
}
is equivalent to this:
x = ListCount(list)
if (x>0) {
item = ListItem(list, GetRandomInt(0, x-1))
}
But I think the latter makes more sense, since "x" is the number of items in the list, which is a reasonable concept - vs. "x" being the number of items - 1, which is a bit weird as a concept. (And I'd rename "x" - or your "result_1" - to be something more friendly, like "count", which is why doing the -1 up front is weird ("count_minus_one"?). The better you can name your variables, the easier it will be for someone to understand your code.)
HegemonKhan
26 Feb 2014, 21:22thanks for the help and advice on better code design, and also, this travel code of mine is old (I did it quite a while ago), and I'll use your suggestions (and hopefully be able to now make it much more short~concise ~ assuming I've improved since I had wrote~done this travel code, as yours is, the next time I work at it or other similiar code designs or functionalities, hehe).
----------
I was getting an item "check" of it either being "0" or "-1" (not sure if I was doing this, wrongly "-1" -ing, to my "list indexes" or "listcounts" ~ I'd have to scour through my code ~ too lazy to do at the moment), so the item was blocked off from being accessed, even though it was still (existing) within the list of items.
---------
just curious, while on the subject:
I presume there must have been some reason to do list indexes starting at "0", else then why do it?, and not just merely an "old tradition" etiquette with~of (from) the early coding days. If there was a reason, what is it? (if you know of course)
(does it have something to do with the arrays or even possibly matrixes~matrices, can't spell, lol)
but, aside from this presuming reason (and my ignorance of it) ... we shouldn't be still using "0" for the start... as it does cause a lot of headaches, surely for many people, and not just me, lol.
----------
I was getting an item "check" of it either being "0" or "-1" (not sure if I was doing this, wrongly "-1" -ing, to my "list indexes" or "listcounts" ~ I'd have to scour through my code ~ too lazy to do at the moment), so the item was blocked off from being accessed, even though it was still (existing) within the list of items.
---------
just curious, while on the subject:
I presume there must have been some reason to do list indexes starting at "0", else then why do it?, and not just merely an "old tradition" etiquette with~of (from) the early coding days. If there was a reason, what is it? (if you know of course)
(does it have something to do with the arrays or even possibly matrixes~matrices, can't spell, lol)
but, aside from this presuming reason (and my ignorance of it) ... we shouldn't be still using "0" for the start... as it does cause a lot of headaches, surely for many people, and not just me, lol.
george
27 Feb 2014, 01:52@HK, http://en.wikipedia.org/wiki/Zero-based_numbering 
Inform and TADS have a few kinds of constructs where you select from a list and then the next time you select you don't get the previous selection. There's one that's random, one that selects in order and stops, and one that selects in order and then starts again at the beginning. I might be forgetting some. Anyway, it seems like it'd be nice to have this added to the text processor, what do people think?

Inform and TADS have a few kinds of constructs where you select from a list and then the next time you select you don't get the previous selection. There's one that's random, one that selects in order and stops, and one that selects in order and then starts again at the beginning. I might be forgetting some. Anyway, it seems like it'd be nice to have this added to the text processor, what do people think?
Liam315
27 Feb 2014, 02:31Sounds like a good idea, I've never made a library before that integrates with the GUI so I'm going to have a crack at it. The only problem I can foresee needing to work around is finding the most appropriate way to store global attributes for multiple lists, i.e. what item the count is up to, the original list minus the used options etc.
george
27 Feb 2014, 04:23I guess you could just make an object for the list of responses, then define attributes on that?
Or maybe a dictionary, then one of the keys could be the count. That would wrap it up nicely.
Or maybe a dictionary, then one of the keys could be the count. That would wrap it up nicely.
Liam315
27 Feb 2014, 04:47george wrote:I guess you could just make an object for the list of responses, then define attributes on that?
This is what I've ended up doing. Just putting the finishing touches on now, considering figuring out how to add it to the list of options that come up under "add script."
HegemonKhan
27 Feb 2014, 10:04obviously, there's tons of resources online, especially video resources, but anyways, I've been watching these videos to try to help me more out with trying to understand code methods and designs better (and~or more of them ~ improve my ways of code thinking and etc), as I feel a bit "stuck" with advancing in learning to code better, and they're a bit interesting for me (and it's also cool that I have already understood from working with quest a lot of the stuff that I've so far watched, hehe), so, anyways, this one video ( http://www.youtube.com/watch?v=Pfo7r6bjSqI ), I just watched this yesterday ~ I'm onto the next video now, lol, talks a bit on this subject:
(maybe Alex already has this stuff implemented... it's an IEEE 7XX standard, forgot the exact number, that is used by a lot of computer languages)
err.. I'm finding that this is just too hard for me to try to explain...
I can only explain this part of it:
let's say we've got a range (a list): 0-10
and you got to guess the right number
you can simply brute force it (iterate through the entire list, aka "foreach"):
is it... 0? 1? 2? 3? 4? 5? 6? 7? 8? 9? 10?
or, you can do this (guess, and then improve upon your next guess):
is it... 5?
okay it's not 5, but is it greater than or less than 5? greater than, you say?
alright, is it... 9?
okay it's not 9, but is it greater than or less than 9? lesser than, you say?
we've now improved (by limiting) our estimation of the right answer:
from range 0-10
to range: 5-9
and we keep doing this.. until we get the right answer, or so close, that we know the answer.
so in terms of a visual:
|_____________|
0..................10
guess ~half: 5
|______|______|
0........5.........10
check~test if it's greater or lesser than 5, let's say it's greater than:
|_______|________|
...........5..........10
guess ~half: 7
|_______|____|____|
...........5......7....10
check~test if it's greater or lesser than 7, let's say it's lesser than:
|_______|____|____|
...........5......7......
guess ~half: 6
|_______|__|__|____|
...........5...6...7......
etc... you get the idea...
anyways, this method (which can be used for numbers and also strings) is similiar to another method for strings:
where, you keep shrinking it, which then means it'll apply to the entire string (sorry, I didn't really get much understanding of this)
but it goes like this:
range (list): ABCDEFGH
take off 1 character from the left and the right:
BCDEFG
again:
CDEF
and again...
DE
though I don't know more... lol... maybe someone else knows what this is for doing, and what else is apart of this.
-------
and the first vid of this MIT computer science 101 vid lecture series:
http://www.youtube.com/watch?v=k6U-i4gXkLM
personally, the professors do a horrible job at teaching~explaining coding (at least the basics of coding anyways)... and these are prestigious MIT professors...
they probably know how to code really well... but teaching~explaining it... they're really awfully bad at it (so far of what I've watched anyways ~ hopefully they get better further into their teaching~explaining of code).
(maybe Alex already has this stuff implemented... it's an IEEE 7XX standard, forgot the exact number, that is used by a lot of computer languages)
err.. I'm finding that this is just too hard for me to try to explain...
I can only explain this part of it:
let's say we've got a range (a list): 0-10
and you got to guess the right number
you can simply brute force it (iterate through the entire list, aka "foreach"):
is it... 0? 1? 2? 3? 4? 5? 6? 7? 8? 9? 10?
or, you can do this (guess, and then improve upon your next guess):
is it... 5?
okay it's not 5, but is it greater than or less than 5? greater than, you say?
alright, is it... 9?
okay it's not 9, but is it greater than or less than 9? lesser than, you say?
we've now improved (by limiting) our estimation of the right answer:
from range 0-10
to range: 5-9
and we keep doing this.. until we get the right answer, or so close, that we know the answer.
so in terms of a visual:
|_____________|
0..................10
guess ~half: 5
|______|______|
0........5.........10
check~test if it's greater or lesser than 5, let's say it's greater than:
|_______|________|
...........5..........10
guess ~half: 7
|_______|____|____|
...........5......7....10
check~test if it's greater or lesser than 7, let's say it's lesser than:
|_______|____|____|
...........5......7......
guess ~half: 6
|_______|__|__|____|
...........5...6...7......
etc... you get the idea...
anyways, this method (which can be used for numbers and also strings) is similiar to another method for strings:
where, you keep shrinking it, which then means it'll apply to the entire string (sorry, I didn't really get much understanding of this)
but it goes like this:
range (list): ABCDEFGH
take off 1 character from the left and the right:
BCDEFG
again:
CDEF
and again...
DE
though I don't know more... lol... maybe someone else knows what this is for doing, and what else is apart of this.
-------
and the first vid of this MIT computer science 101 vid lecture series:
http://www.youtube.com/watch?v=k6U-i4gXkLM
personally, the professors do a horrible job at teaching~explaining coding (at least the basics of coding anyways)... and these are prestigious MIT professors...
they probably know how to code really well... but teaching~explaining it... they're really awfully bad at it (so far of what I've watched anyways ~ hopefully they get better further into their teaching~explaining of code).

jaynabonne
27 Feb 2014, 13:04HK, that sounds like a binary search. What you're searching needs to be sorted in some fashion, though, so you can make "greater than" and "less than" choices to decide which half of the remaining search space to look at next.
Liam315
28 Feb 2014, 02:40george wrote:Inform and TADS have a few kinds of constructs where you select from a list and then the next time you select you don't get the previous selection. There's one that's random, one that selects in order and stops, and one that selects in order and then starts again at the beginning. I might be forgetting some. Anyway, it seems like it'd be nice to have this added to the text processor, what do people think?
I've posted the library here: viewtopic.php?f=18&t=4207&p=28008#p28008
michaelsahn
28 Feb 2014, 19:50This has been very helpful and I am putting the code to good use - thanks!
Mike
Mike