showmenu and dictionary don't mix well, how? #1673
|
Hi, I’m trying to use a StringDictionary with ShowMenu for NPC dialogue. Example: Dictionary documentation: Pixie's conversations: Observation: Why not list?: p.s. I am flexible, if there are other simpler ways that reduces lots of coding in npc dialogues, I can switch to that. |
Replies: 6 comments 8 replies
|
where are your object’s script attributes? the player object needs the scripts getthing, jump and vomit |
|
Sorry, but I don't get it. What can a string dictionary do that a string list can't? In a conversation, you want to give the player several options to choose from. There need to be scripts associated with these options that return a response. There are several ways to do this. Which one do you want to use? |
|
But is it enough to just display a message? Or shouldn't you instead call a script for each item to process the input? |
|
Oh you did it before. Just two ways to do it: |
|
Just playing around with things we could do with Mainly, when you SPEAK TO someone, it will display a menu with all the ASK, TELL, and ORDER (tellto) options for the object. <!--Saved by Quest 5.9.9166.36226-->
<asl version="580">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="ShowMenu Shennanigans">
<gameid>9493ef09-5ef6-4b0f-9418-180a35f16534</gameid>
<version>0.1 alpha</version>
<firstpublished>2026</firstpublished>
<feature_asktell />
<start type="script"><![CDATA[
frog.hop => {
msg ("The frog hops in place.")
}
frog.ribbit => {
msg ("The frog ribbits.")
}
game.statusattributes = NewStringDictionary()
dictionary add (game.statusattributes, "moves", "Moves: !")
game.moves = 0
]]></start>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<object name="frog">
<inherit name="editor_object" />
<takemsg>{random:It's too slippery.:It hops out of reach before you can get it.:{=CapFirst(GetDefiniteName(frog))} might not like that.}</takemsg>
<speak type="script"><![CDATA[
SuppressTurnscripts
opts = NewStringList()
if (HasAttribute (this, "ask")) {
foreach (key, this.ask) {
list add (opts, "Ask " + GetDefiniteName(this) + " about " + StringListItem(Split(key, " "), 0) + "")
}
}
if (HasAttribute (this, "tell")) {
foreach (key, this.tell) {
list add (opts, "Tell " + GetDefiniteName(this) + " about " + StringListItem(Split(key, " "), 0) + "")
}
}
if (HasAttribute (this, "tellto")) {
foreach (key, this.tellto) {
list add (opts, "Tell " + GetDefiniteName(this) + " to " + StringListItem(Split(key, " "), 0) + "")
}
}
ShowMenu ("OPTIONS:", opts, false) {
msg (">> " + LCase(result))
HandleSingleCommand (result)
}
]]></speak>
<tellto type="scriptdictionary">
<item key="hop">
msg (CapFirst(GetDefiniteName(this)) + " hops in place.")
</item>
<item key="jump">
invoke (ScriptDictionaryItem(this.tellto, "hop"), QuickParams("this",this))
</item>
<item key="ribbit speak talk">
msg ("The frog says, \"ribbit!\"")
</item>
</tellto>
<ask type="scriptdictionary">
<item key="lillypads">
msg ("The frog seems happy to talk about lillypads. \"Ribbit,\" says the frog, as if to confirm this.")
</item>
</ask>
</object>
</object>
<command name="v_test">
<pattern>test</pattern>
<script><![CDATA[
SuppressTurnscripts
testdic = NewStringDictionary()
dictionary add (testdic, "x me", "Examine yourself.")
dictionary add (testdic, "jump", "Jump in place.")
if (frog.parent = game.pov.parent) {
dictionary add (testdic, "x frog", "Get a good look at the frog.")
}
ShowMenu ("Choose a command.", testdic, false) {
msg (">> " + LCase(result))
HandleSingleCommand (result)
}
]]></script>
</command>
<turnscript name="ts_test">
<enabled />
<script>
if (not HasAttribute (game, "moves")) {
game.moves = 0
}
game.moves = game.moves + 1
</script>
</turnscript>
</asl> |
|
I won't play with this anymore after this, I promise. (; ... but here's one last example game, with yet another approach. It works. It's not as good as just using <!--Saved by Quest 5.9.9166.36226-->
<asl version="580">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Even More ShowMenu Shennanigans">
<gameid>97e08b9f-ff58-4665-972c-4ceed264af45</gameid>
<version>1.0</version>
<firstpublished>2026</firstpublished>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<object name="frob">
<inherit name="editor_object" />
<take />
</object>
</object>
<object name="box">
<inherit name="editor_object" />
<inherit name="container_closed" />
<feature_container />
<listchildren />
<isopen />
</object>
</object>
<command name="v_test">
<pattern>test</pattern>
<script><![CDATA[
dic = NewStringDictionary()
dictionary add (dic, "jump", "Try jumping.")
dictionary add (dic, "lookat|object=player", "Try examining yourself.")
dictionary add (dic, "put|object1=frob,object2=box", "Try putting the frob in the box.")
ShowMenu ("CHOOSE!", dic, false) {
if (Instr(result, "|") > 0) {
parts = Split(result,"|")
cmd = GetObject (StringListItem (parts, 0))
dicstuff = StringListItem(parts,1)
qdic = NewDictionary()
foreach (pair, Split(dicstuff, ",")) {
key_entry = Split(pair, "=")
key = StringListItem (key_entry,0)
entry = GetObject (StringListItem (key_entry, 1))
if (entry = null) {
entry = StringListItem (key_entry, 1)
if (entry = "game.pov") {
entry = game.pov
}
}
dictionary add (qdic, key, entry)
}
invoke (cmd.script, qdic)
}
else {
cmd = GetObject(result)
invoke (cmd.script)
}
}
]]></script>
</command>
</asl> |
Just playing around with things we could do with
ShowMenu... Here is a little test game with a few different approaches.Mainly, when you SPEAK TO someone, it will display a menu with all the ASK, TELL, and ORDER (tellto) options for the object.