Mods: Jay's right, this should go into the 'libraries and code samples' forum, if you could move this thread over there, it'd be much appreciated.
--------------------------------
here's an example of using dictionaries for conversion (input -> output):
(if you don't like the popup window when using 'show menu', there's this code of mine, hehe. Though, do note that there's a better way to do this, see Pixie's post below on the details of it. This is an example only for helping people understand how dictionaries work)
(HK edit: code is fixed, thanks Pixie for spotting my mistakes!)
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="testing game stuff">
<gameid>619916da-ce93-495d-82c3-a69ae10f37d2</gameid>
<version>1.0</version>
<author>HK</author>
<start type="script">
race_string_character_creation_function
</start>
<attr name="race_stringdictionary" type="simplestringdictionary">1=human; 2=dwarf; 3=elf; 4=gnome; 5=halfling</attr>
</game>
<function name="race_string_character_creation_function"><![CDATA[
msg ("What is your race? (Please type in the number of the race you want)")
msg ("(1) human, (2) dwarf, (3) elf, (4) gnome, or (5) halfling")
get input {
if (ToInt (result) > 0 and ToInt (result) < 6) {
player.race_string = StringDictionaryItem (game.race_stringdictionary, result)
msg ("Race: " + player.race_string)
wait {
ClearScreen
}
} else {
ClearScreen
race_string_character_creation_function
}
}
]]></function>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
</object>
</asl>
what the dictionary allows for (via 'StringDictionaryItem' ) is CONCEPTUALLY:
if (input: result = 1) -> (and its conversion is: 1 = human) -> then (output: human)
if (input: result = 2) -> (and its conversion is: 2 = dwarf) -> then (output: dwarf)
if (input: result = 3) -> (and its conversion is: 3 = elf) -> then (output: elf)
if (input: result = 4) -> (and its conversion is: 4 = gnome) -> then (output: gnome)
if (input: result = 5) -> (and its conversion is: 5 = halfling) -> then (output: halfling)
<attr name="race_stringdictionary" type="simplestringdictionary">dragon=The dragon has kidnapped the princess, and it can only be killed by the legendary dragon slaying sword. ; evil wizard=The evil wizard guards the legendary dragon slaying sword.</attr>
if (input: result = "dragon") -> (conversion) -> then (output 'msg' Script: "The dragon has kidnapped the princess, and it can only be killed by the legendary dragon slaying sword.")
if (input: result = "evil wizard") -> (conversion) -> then (output 'msg' Script: "The evil wizard guards the legendary dragon slaying sword.")
-------------
Object Dictionaries are the exact same as String Dictionaries, except their output is an Object (instead of just a string:text)
'ObjectDictionaryItem'
if (input string: "apple"), then (output object: apple)
Script Dictionaries are the exact same as String Dictionaries, except their output can be ANY (and as MANY) Scripts (not just limited to a single msg script like the String Dictionary is at its coding core) that (and as) you want.
'ScriptDictionaryItem'
if (input string: "apple"), then (output scripts: see below)
player.hp = player.hp + 50
if (player.hp > 999) {
player.hp = 999
}
msg ("You eat the apple, regaining 50 hp")
if (input string: "poisoned apple"), then (output scripts: see below)
msg ("You eat the poisoned apple, losing 50 hp")
player.hp = player.hp - 50
if (player.hp <= 0) {
msg ("GAME OVER")
finish