Creating "New" Dictionaries
TriangleGames
07 Mar 2013, 14:44I actually found a way to make my scripts do what I want, but I'm perplexed by why it did not work the way I tried it originally.
I'm using a StringDictionary named "view" to hold a selection of possible things seen out a window.
(I have a function set up to convert int's to string's, so I can use GetRandomint to choose what dictionary item is printed out.)
Assuming that I would only need to create and fill the dictionary once, I put the declaration and item definitions in a "FirstTime" script, like so...

But when I played it, it only recognized the dictionary name "view" the first time I looked at the window.
Every time after that, it gave me an error, "Unknown object or variable 'view'."
So, I got rid of the "FirstTime" script, and let it just do the whole thing every time I look at the window, Like so...

It seems to work just fine this way, but I'm confused as to why it did not work the other way.
Once a "new StringDictionary" has been created, shouldn't it be accessible at any time later?
It feels weird to "create" the same "new" dictionary repeatedly. Wouldn't it waste extra memory on redundant copies of the dictionary?
EDIT: BTW, is there already a method for converting int's to string's that can be used in Quest? My "IntString" function uses a switch with a separate case for each number. Right now it can only handle numbers 1 through 5.
I'm using a StringDictionary named "view" to hold a selection of possible things seen out a window.
(I have a function set up to convert int's to string's, so I can use GetRandomint to choose what dictionary item is printed out.)
Assuming that I would only need to create and fill the dictionary once, I put the declaration and item definitions in a "FirstTime" script, like so...

But when I played it, it only recognized the dictionary name "view" the first time I looked at the window.
Every time after that, it gave me an error, "Unknown object or variable 'view'."
So, I got rid of the "FirstTime" script, and let it just do the whole thing every time I look at the window, Like so...

It seems to work just fine this way, but I'm confused as to why it did not work the other way.
Once a "new StringDictionary" has been created, shouldn't it be accessible at any time later?
It feels weird to "create" the same "new" dictionary repeatedly. Wouldn't it waste extra memory on redundant copies of the dictionary?
EDIT: BTW, is there already a method for converting int's to string's that can be used in Quest? My "IntString" function uses a switch with a separate case for each number. Right now it can only handle numbers 1 through 5.
levicki
07 Mar 2013, 14:55Your variable view is local. If you put it in FirstTime it lives only in that if () scope. Also, if you create it in a script, it is visible only in that script and exists while the script is executed which means it does not get created multiple times (you can check in debugger to see how many you have).
In order to have persistent dictionaries or lists you would need to create them at the start of the game and assign them to some global variables.
In order to have persistent dictionaries or lists you would need to create them at the start of the game and assign them to some global variables.
TriangleGames
07 Mar 2013, 14:59Oh, well that makes sense. I guess I've been thinking of "scope" in game terms so much that I forgot programs have scopes too, lol.
Thank you for clearing that up, I'm sure it'll very helpful in the future.
Thank you for clearing that up, I'm sure it'll very helpful in the future.
HegemonKhan
07 Mar 2013, 15:12yep, your "view" simply needs to be changed to:
game.view, game.pov.view, or object.view
(technically, these are all object.view 's lol)
I make this mistake all the time myself, due to forgetting to add the needed permanent location (so it's not a local variable) to it, lol.
-------------
I'm trying to figure out how to use dictionaries myself, I got a question about them in the Noob HK Help Me thread, that no one has answered yet, though I think I figured out how to use them on my own (hopefully), but I haven't tested using them (well my methods~attempts of using them, lol) yet on my own.
I don't think you should need the IntString converter function...
my understanding is that the
DictionaryItem, StringDictionaryItem, ObjectDictionaryItem, and ScriptDictionaryItem, RETURNS the value (strings, objects, or scripts) for you, upon choosing (such as via randomly) its keys (1,2,3,etc or one,two,three,etc or red,blue,yellow,etc or whatever strings).
It took me along time to figure out how to add a ScriptDictionary item, lol.
I'm like how do I write a script into its code ???
code (I think) = dictionary add (dictionary,key,value)
then I finally realized, to make a script code, and thus I could just plug in its name to the value:
<move type="script">
yada yada yada
</move>
dictionary add (travel_object_structure.travel_dictionary,home,move)
---------
here's the questions I was asking on the other thread:
I was asking if people could look over this code of mine, and see if it would work or not, and etc.
(I think I've since figured out how to properly use dictionaries, lists, and etc, but I still haven't gotten around to testing it yet)
(this was written prior to me figuring out how to hopefully do the stuff correctly, lol. this was before I realized to make a script code, so I could add it into the add dictionary code via its name)
game.view, game.pov.view, or object.view
(technically, these are all object.view 's lol)
I make this mistake all the time myself, due to forgetting to add the needed permanent location (so it's not a local variable) to it, lol.
-------------
I'm trying to figure out how to use dictionaries myself, I got a question about them in the Noob HK Help Me thread, that no one has answered yet, though I think I figured out how to use them on my own (hopefully), but I haven't tested using them (well my methods~attempts of using them, lol) yet on my own.
I don't think you should need the IntString converter function...
my understanding is that the
DictionaryItem, StringDictionaryItem, ObjectDictionaryItem, and ScriptDictionaryItem, RETURNS the value (strings, objects, or scripts) for you, upon choosing (such as via randomly) its keys (1,2,3,etc or one,two,three,etc or red,blue,yellow,etc or whatever strings).
It took me along time to figure out how to add a ScriptDictionary item, lol.
I'm like how do I write a script into its code ???
code (I think) = dictionary add (dictionary,key,value)
then I finally realized, to make a script code, and thus I could just plug in its name to the value:
<move type="script">
yada yada yada
</move>
dictionary add (travel_object_structure.travel_dictionary,home,move)
---------
here's the questions I was asking on the other thread:
I was asking if people could look over this code of mine, and see if it would work or not, and etc.
(I think I've since figured out how to properly use dictionaries, lists, and etc, but I still haven't gotten around to testing it yet)
(this was written prior to me figuring out how to hopefully do the stuff correctly, lol. this was before I realized to make a script code, so I could add it into the add dictionary code via its name)
<library>
<!-- Commands -->
<command name="help_command">
<pattern>help</pattern>
<script>
help_function
</script>
</command>
<command name="statistics_command">
<pattern>stats</pattern>
<script>
statistics_function
</script>
</command>
<command name="explore_command">
<pattern>explore</pattern>
<script>
explore_function
</script>
</command>
<command name="travel_command">
<pattern>goto</pattern>
<script>
travel_function
</script>
</command>
<command name="storage_command">
<pattern>storage</pattern>
<script>
storage_function
</script>
</command>
<command name="equipment_command">
<pattern>gear</pattern>
<script>
equipment_function
</script>
</command>
<!-- Functions -->
<function name="help_function">
</function>
<function name="statistics_function">
</function>
<function name="explore_function">
switch (game.pov.parent) {
case ("homeland") {
if (firsttime) {
ScriptDictionaryItem (dictionary_structures.homeland_events_script_dictionary,"homeland_discovery")
} otherwise {
ScriptDictionaryItem (dictionary_structures.homeland_events_script_dictionary,GetRandomInt(1,max_value))
}
}
}
</function>
<function name="travel_function">
show menu ("Where do you wish to travel?",dictionary_structures.travel_script_dictionary,true) {
ScriptDictionaryItem (dictionary_structures.travel_script_dictionary,result)
}
</function>
<function name="storage_function">
</function>
<function name="equipment_function">
</function>
<function name="travel_script_dictionary_function"><![CDATA[
if (boolean_structures.homeland_discovered = true) {
dictionary add (dictionary_structures.travel_script_dictionary,"homeland", etc etc and script (if (game.pov.parent <> homeland) then script (game.pov.parent = homeland))
}
]]></function>
<function name="game_turns_function">
game.turns = game.turns + 1
</function>
<!-- Turnscripts -->
<turnscript name="game_turns_turnscript">
travel_script_dictionary_function
game_turns_function
</turnscript>
<!-- Object Structures (Data Storage) -->
<object name="dictionary_structures">
<parent>null</parent>
<travel_script_dictionary type="scriptdictionary">
<item key="homeland"><![CDATA[
if (game.pov.parent = homeland) {
msg ("You are already here at the homeland! Try again.")
wait {
travel_function
}
} else if (game.pov.parent <> homeland) {
game.pov.parent = homeland
]]></item>
</travel_script_dictionary>
<homeland_events_script_dictionary type="scriptdictionary">
<item key="homeland_discovery">
boolean_structures.homeland_discovered = true
msg ("You've discovered the homeland! Now, you can truly explore, and also travel to, the homeland!")
</item>
</homeland_events_script_dictionary>
</object>
</library>
Alex
07 Mar 2013, 15:14You can convert a string to an int using ToInt()