String Dictionary and Show menu
greenelvish
09 Feb 2012, 15:50Hi,
if I set a string dictionary (called "pensieri") and a show menu script (with options taken from "pensieri") and then I put both dictionary and script in the same function, everything works.
But if - in order to manage items in a better way - I set the same string dictionary (copy and paste) in the Start Script (among other actions)
and then I create a function with the same show menu script (copy and paste) with options taken from "pensieri",
Quest says: "Error running script: Unknown object or variable 'pensieri' ". And sometimes it crashes.
I think I'm doing something wrong...
Thank you
if I set a string dictionary (called "pensieri") and a show menu script (with options taken from "pensieri") and then I put both dictionary and script in the same function, everything works.
<function name="dialogo"><![CDATA[
pensieri = NewStringDictionary()
dictionary add (pensieri, "aggressione", "Potresti aggredire quell'uomo e costringerlo a dirti come si fa ad uscire.")
dictionary add (pensieri, "domanda", "Potresti anche solo chiedergli come si fa ad uscire.")
dictionary add (pensieri, "aspetta", "Potresti infine restare dove sei, e attendere che sia lui ad accorgersi di te.")
show menu ("Senti di essere vicino alla salvezza, ma devi scegliere con cura le tue ultime mosse:", pensieri, true) {
switch (result) {
case ("aggressione") {
msg ("La tensione si trasforma in rabbia e la rabbia si trasmette al tuo corpo. Tutto avviene cosi' velocemente che quasi non ti accorgi di iniziare a correre per aggredire quell'uomo. <br/><br/> Succede pero' anche che ti schianti contro una parete di vetro... praticamente invisibile, tanto era pultia e trasparente.")
player.cavia = 1
muori_per_scherzo
}
case ("domanda") {
msg ("Ti avvicini un po' e poi chiedi: 'Mi scusi, saprebbe dirmi come si esce da qui?' <br/><br/> Senza muoversi di un millimetro, l'uomo risponde con una strana voce gracchiante e metallica: 'Ho sete, ragazzo mio. Puoi fare niente per me?'")
}
case ("aspetta") {
msg ("Aspetti immobile e in silenzio, confidando che prima o poi l'uomo si voltera'. Nel frattempo, ti viene voglia di esaminare i dettagli della stanza.")
EnableTimer (aspetta)
}
}
}
]]></function>
But if - in order to manage items in a better way - I set the same string dictionary (copy and paste) in the Start Script (among other actions)
<start type="script">
pensieri = NewStringDictionary()
dictionary add (pensieri, "aggressione", "Potresti aggredire quell'uomo e costringerlo a dirti come si fa ad uscire.")
dictionary add (pensieri, "domanda", "Potresti anche solo chiedergli come si fa ad uscire.")
dictionary add (pensieri, "aspetta", "Potresti infine restare dove sei, e attendere che sia lui ad accorgersi di te.")
game.displayroomdescriptiononstart = false
insert ("descrizione_intro_1.html")
wait {
insert ("descrizione_intro_2.html")
wait {
OnEnterRoom (null)
}
}
</start>
and then I create a function with the same show menu script (copy and paste) with options taken from "pensieri",
</function>
<function name="dialogo"><![CDATA[
show menu ("Senti di essere vicino alla salvezza, ma devi scegliere con cura le tue ultime mosse:", pensieri, true) {
switch (result) {
case ("aggressione") {
msg ("La tensione si trasforma in rabbia e la rabbia si trasmette al tuo corpo. Tutto avviene cosi' velocemente che quasi non ti accorgi di iniziare a correre per aggredire quell'uomo. <br/><br/> Succede pero' anche che ti schianti contro una parete di vetro... praticamente invisibile, tanto era pultia e trasparente.")
player.cavia = 1
muori_per_scherzo
}
case ("domanda") {
msg ("Ti avvicini un po' e poi chiedi: 'Mi scusi, saprebbe dirmi come si esce da qui?' <br/><br/> Senza muoversi di un millimetro, l'uomo risponde con una strana voce gracchiante e metallica: 'Ho sete, ragazzo mio. Puoi fare niente per me?'")
}
case ("aspetta") {
msg ("Aspetti immobile e in silenzio, confidando che prima o poi l'uomo si voltera'. Nel frattempo, ti viene voglia di esaminare i dettagli della stanza.")
EnableTimer (aspetta)
}
}
}
]]></function>
Quest says: "Error running script: Unknown object or variable 'pensieri' ". And sometimes it crashes.
I think I'm doing something wrong...
Thank you

Pertex
09 Feb 2012, 16:32If you use "pensieri = NewStringDictionary()" you are creating a local dictionary which is only known in this object. All other objects (and scripts) do not know this dictionary. So you have to add an objectname to the dictionary, where the dictionary is created/saved. Try to replace "pensieri" with "game.pensieri" whereever you use your dictionary, then its saved im the gameobject.
and
game.pensieri = NewStringDictionary()
dictionary add (game.pensieri, "aggressione", "Pot... uscire.")
...
and
</function>
<function name="dialogo"><
Now I know a new thing about Quest.
