Switch and String Dictionary issues [solved]

greyst0ke
27 Jun 2014, 03:35
Hi all,

I seem to have encountered a weird issue that I can't quite work out.
I'm trying to build dialogue libraries so my code doesn't end up a mess of if/else/print statements. So, what I did was...

make a game.dialogue object . In the dialogue object I have attributes for conversations (script dictionaries) and responses (string dictionaries)

I have a situation where it's working in one spot and not in another though they seem identical.

I'm calling the StringDictionaryItem directly for both the menulist entries and as the case to match in the switch blocks.

Ignore the actual text, it's just to see if doing it this way is a good plan....

First the string dictionary:
dialogue.tlk002

Key Value
00101 Same old, same old... Just working too much.
00102 Living the dream dude... living the dream.
30101 I've always been too good for this place
30102 I couldn't keep away from you Gloria

This works...

replylist = NewStringList()
list add (replylist, StringDictionaryItem(dialogue.tlk0002, "00101"))
list add (replylist, StringDictionaryItem(dialogue.tlk0002, "00102"))
ShowMenu ("You snap back with...", replylist, false) {
switch (result) {
case (StringDictionaryItem(dialogue.tlk0002, "00101")) {
msg ("[Andy] Man you're boring")
}
case (StringDictionaryItem(dialogue.tlk0002, "00102")) {
msg ("Oh? Do tell!")
}
}
}



In game:

[Andy] Well if you've missed me that much, who am I to judge. So what's been happening brotherman? Sharing is caring, am I right?
You snap back with...
1: Same old, same old... Just working too much. <--- select
2: Living the dream dude... living the dream.

[Andy] Man you're boring <--- result




The ScriptDictionaryItem is printed in the menu and successfully resolves in the switch and the result is printed.

This one however doesn't work.

replylist2 = NewStringList()
list add (replylist2, StringDictionaryItem(dialogue.tlk0002, "30101"))
list add (replylist2, StringDictionaryItem(dialogue.tlk0002, "30102"))
ShowMenu ("You reply", replylist2, false) {
switch (result) {
case (StringDictionaryItem(dialogue.tlk0002, "30101")) {
msg ("You and me both...")
}
case (StringDictionaryItem(dialogue.tlk0002, "30102")) {
msg ("You smooth talker...")
}
}
}


In game:

Well i'll be... haven't seen you in a while.
Too good for old Murdo's now huh?

You reply
1: I've always been too good for this place
2: I couldn't keep away from you Gloria



The menu text is printed from the dictionary correctly and the menu is displayed however selecting either option does nothing.
No error is generated but the switch never resolves the case. (Typing 1 or 2 manually resolves it of course)

Am I missing something obvious?

Ultimately I want all the cases to print entries from the String Dictionary as well but I seem to be stuck at the first hurdle.

greyst0ke
27 Jun 2014, 03:38
Oh and if you look at the gamefile, walkthrough2 will get you to the point

Pertex
27 Jun 2014, 06:05
Sorry, but I don't get to this dialogue. convGloria2 is not called in your game

jaynabonne
27 Jun 2014, 06:32
Someone else ran into this recently. It seems Quest doesn't like menu items that have apostrophes in them. You can work around it by removing the apostrophe, but you might be better off in general switching to the dictionary form of ShowMenu. It will make your code cleaner and avoid the problem.

ShowMenu can take either a list of items to show or a dictionary of items to show. If it's a dictionary, the values are shown as usual, but the key for the chosen value is what's returned in the result. Something like:

replies = NewStringDictionary()
dictionary add (replies , "reply1", StringDictionaryItem(dialogue.tlk0002, "30101"))
dictionary add (replies , "reply2", StringDictionaryItem(dialogue.tlk0002, "30102"))
ShowMenu ("You reply", replies , false) {
switch (result) {
case ("reply1") {
msg ("You and me both...")
}
case ("reply2") {
msg ("You smooth talker...")
}
}
}


Just be sure to not put any apostrophes in the keys. :) Hope that helps!

Edit: in fact, you could simply have separate canned string dictionaries for each set of dialogue and not even have to create a new dictionary each time - just point to the one with the answers for that instance. If that makes sense...

greyst0ke
27 Jun 2014, 10:31
Pertex wrote:Sorry, but I don't get to this dialogue. convGloria2 is not called in your game


ack.. sorry was so caught up in trying to explain the issue clearly i forgot to say how to invoke it in the gamefile... my bad.

The walkthrough2 takes you to the first example. The one that works.

Talking to gloria (after the first has run through) invokes the second example that doesn't work.

greyst0ke
27 Jun 2014, 10:34
jaynabonne wrote:Someone else ran into this recently. It seems Quest doesn't like menu items that have apostrophes in them.


Ahhh ok. That might be it.... Thanks for the heads up. Will see if that makes a difference.

Thanks for the pointer on using dictionaries instead of building new lists too. That may simplify things a bit.

greyst0ke
27 Jun 2014, 10:46
jaynabonne wrote:It seems Quest doesn't like menu items that have apostrophes in them


Removing the apostrophes works a treat! Not ideal but workable.

Thank you!!! Was driving me crazy!