Helping with character speaking interaction.

This is problably answered somewhere in the fourms but i'm trying to get this section of code to work and it does but the switch statement doesn't impliment the message script when any of the options are chosen the menu just dissapperes it's probably something very easy to fix and i haven't found out how yet. Maybe it's cause they are strings? Or something like that... maybe I need a dictionary instead? To hold the alias's maybe...

list add (options, "\"Hey {Player1.alias}!\"")
list add (options, "\"{Player1.alias}? Shouldn't you be inside already?\"")
ShowMenu ("\"Your Response?\"", options, false) {
  switch (result) {
    case ("{Player1.alias}? Shouldn't you be inside already?") {
      msg ("tesst<br/>")
    }
    case ("Hey {Player1.alias}!") {
      msg ("test ")
    }
 }
} ``

When the messages are sent to the player, the text processor runs on them and converts {Player1.alias} to whatever the alias is.

If the player types the number of the option in the menu, then result will be the string "Hey {Player1.alias}!" (which was stored ). If they click on the option, then result will be something like "Hey Bob!".

Solution 1: Force the text processor to run on the string, so that the case statements match the string that is sent back from the browser.

Example:

    case (ProcessText ("\"{Player1.alias}? Shouldn't you be inside already?\"")) {

The downside of this is that typing the option numbers will no longer work (though I don't think most players know they can do that anyway).


Solution 1a: Use both the text processor, and the regular string, to catch both options.
For example:

    case (ProcessText ("\"{Player1.alias}? Shouldn't you be inside already?\""), "\"{Player1.alias}? Shouldn't you be inside already?\"") {

However, this means that if you correct a typo in one of the options, or change it at all, you now have to make the change in 3 places instead of 2. That's how mistakes creep in later in development; and I think you should try to avoid mistakes if possible.


Solution 1b: Make sure the text processor runs earlier, so that result is the same in both cases.
For example:

list add (options, ProcessText ("\"{Player1.alias}? Shouldn't you be inside already?\""))

and

    case (ProcessText ("\"{Player1.alias}? Shouldn't you be inside already?\"")) {

But that's still a little unwieldy.


Solution 2: (the programmer's way of doing it)

My preferred solution would be to use the dictionary version of ShowMenu:

options = NewStringDictionary()
dictionary add (options, "greeting", "\"Hey {Player1.alias}!\"")
dictionary add (options, "inside", "\"{Player1.alias}? Shouldn't you be inside already?\"")
ShowMenu ("\"Your Response?\"", options, false) {
  switch (result) {
    case ("inside") {
      msg ("tesst<br/>")
    }
    case ("greeting") {
      msg ("test ")
    }
  }
} 

You can give the options whatever simple labels you want, and the player never sees them. That also means that if you come to change the spelling of one of the options, or some other cosmetic change later in development, you only need to change it in one place. A lot easier to avoid bugs that way.


the 'cases' must match up exactly with your String List's string options/items:

"\"Hey {Player1.alias}!\""

is NOT the same as

"Hey {Player1.alias}!"

the top line (string value), has double quote characters in the string, via the double quote escape command: \"

whereas, the below line (string value) does NOT have double quote characters in the string

-------

A String Value, is anything encased within double quotes, some examples:

"hi"
"123"
"hi my name is HK, what is your name?"
"hi123"
"hi_123"

// the displayment/output of the above
hi
123
hi my name is HK, what is your name?
hi123
hi_123

the outermost double quotes, tell quest that it is a String Value

so, in order to have double quotes as part of the String Value itself, you must use the double quote escape command, \", which tells quest that the double quotes are to be part of the string itself, and not as double quotes for quest's internal parsing of it, and of course it must be within the outermost double quotes:

"\"hi\""
"\"123\""
"\"hi my name is HK, what is your name?\""
"1\"2\"3"
"hi my \"name\" is \"HK\", what is \"your\" name?"

// the displayment/output of the above
"hi"
"123"
"hi my name is HK, what is your name?"
1"2"3
hi my "name" is "HK", what is "your" name?

so....

// String Value: "hi"
// output/displayment: hi

is NOT the same as:

// String Value: "\"hi\""
// output/displayment: "hi"

so, here's the fix:

options = NewStringList () // possibly needed if quest doesn't already know that the 'options' is a String List, otherwise, you can ignore this line (don't put it in)

list add (options, "\"Hey {Player1.alias}!\"")
list add (options, "\"{Player1.alias}? Shouldn't you be inside already?\"")
ShowMenu ("\"Your Response?\"", options, false) {
  switch (result) {
    case ("\"{Player1.alias}? Shouldn't you be inside already?\"") {
      msg ("test 1<br/>")
    }
    case ("\"Hey {Player1.alias}!\"") {
      msg ("test 2")
    }
 }
}

also, you may want to make your String List be an Attribute (so it can be used/re-used anywhere/anytime), an example:

create ("example_object") // this just creates an Object for this example, but you can use whatever Object you want, such as the 'game' Object, or if it's dialogue specific to a npc, then use that npc as the Object (holding its own dialogue list of options, this is what Attribute VARIABLES are: they're contained within an Object, so as long as the Object exists or still exists, you can use it anywhere, over and over again, whereas a Variable VARIABLE, like your 'option', only exists within that scripting that it's used for and only when the scripting is being used/done/activating)

example_object.options = NewStringList () // possibly needed if quest doesn't already know that the 'example_object.options' is a String List Attribute, otherwise, you can ignore this line (don't put it in)

list add (example_object.options, "\"Hey {Player1.alias}!\"")
list add (example_object.options, "\"{Player1.alias}? Shouldn't you be inside already?\"")
ShowMenu ("\"Your Response?\"", example_object.options, false) {
  switch (result) {
    case ("\"{Player1.alias}? Shouldn't you be inside already?\"") {
      msg ("test 1<br/>")
    }
    case ("\"Hey {Player1.alias}!\"") {
      msg ("test 2")
    }
 }
}

Please change

    }
    case ("Hey {Player1.alias}!") {
      msg ("test ")
    }
 }
} ``

To

    }
    case ("Hey {Player1.alias}!") {
      msg ("test ")
    }
  }
}

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums