Trouble getting all option of a show menu to work

So I have done this code many time and it has always worked pefectly, but not it's not. I'm trying to show a menu to ask what gender your character is, but when I select the option of female it doesn't carry out the assigned code, only on the male or first option. Here is the code I used

options = Split("Male; Female", ";")
      ShowMenu ("What gender is your character?", options, false) {
        switch (result) {
          case ("Male") {
            msg ("So your character is a man.")
            player.sex_type = "male"
          }
          case ("Female") {
            msg ("So your character is a women.")
            player.sex = "female"
          }
          }
        }

Any ideas why this is? I might be where I placed it in the rest of the code which I can also provide if needed.


the nightmare of spaces...

notice in your

options = Split("Male; Female", ";")

there's a space in the 2nd item:

options = Split("Male;[SPACE]Female", ";")

a space is actually considered/seen as a character/number/symbol, just as 'A' and '1' and '&'are seen/considered as characters/numbers/symbols

so, quest is seeing the item/value as:

[SPACE]Female

and not as:

Female

so, this is why your check of:

case ("Female")

fails, as it's looking for 'Female', but there's no 'Female', only '[SPACE]Female'

amusingly, this will work:

case (" Female")

as now we're checking for a value/item that exists:

case ("[SPACE]Female")

laughs, but you don't want '[SPACE]Female' as your sex value, lol


here's the fixed code:

options = Split("Male;Female", ";")
ShowMenu ("What gender is your character?", options, false) {
  switch (result) {
    case ("Male") {
      msg ("So your character is a man.")
      player.sex_type = "male"
    }
    case ("Female") {
      msg ("So your character is a women.")
      player.sex = "female"
    }
  }
}

P.S.

here's just improved code (reduced code: removed un-needed code: made it more concise: you don't need the 'switch-case' code) of your code:

options = Split("male;female", ";")
ShowMenu ("What gender is your character?", options, false) {
  msg ("So your character is a " + result + ".")
  player.sex_type = result
}

or, if you really want your list items to be capitolized (and-but not your sex values):

options = Split("Male;Female", ";")
ShowMenu ("What gender is your character?", options, false) {
  result = LCase (result)
  msg ("So your character is a " + result + ".")
  player.sex_type = result
}

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

Support

Forums