Menu with different outcomes

Xilefenko
18 Oct 2016, 17:22

I want a menu that displays different texts based on what you choose.

How can you do that?


onimike
18 Oct 2016, 17:54

You could do some thing like this where i have a basic transportation menu as a function called "mapmenu" asking which system a person wants to go to

mapmenu= NewStringList()
list add (mapmenu, "Starsystem1")
list add (mapmenu, "Starsystem2")
list add (mapmenu, "Starsystem3")
ShowMenu ("Choose your class...", mapmenu, true) {
  msg ("You choose " +result+".")
  if (result<>null) {
    if (result = "Starsystem1") {
      Ask ("Are you sure you want to be a " +result+"?") {
        if (result = True) {
          MoveObject (player, Starsystem1)
                }
        else if (result = False) {
          mapmenu
        }
      }
    }
    else if (result = "Starsystem2") {
      Ask ("Are you sure you want to be a " +result+"?") {
        if (result = True) {
               Ask ("Are you sure you want to be a " +result+"?") {
        if (result = True) {
          MoveObject (player, Starsystem2)
                }
        else if (result = False) {
          mapmenu
        }
      }
    }
    else if (result = "Starsystem3") {
      Ask ("Are you sure you want to be a " +result+"?") {
        if (result = True) {
                Ask ("Are you sure you want to be a " +result+"?") {
        if (result = True) {
          MoveObject (player, Starsystem3)
                }
        else if (result = False) {
          mapmenu
        }
      }
    }
  }
  else {
    msg ("You choose to cancel..")
  }
}

Xilefenko
18 Oct 2016, 18:15

thanks


hegemonkhan
18 Oct 2016, 19:06

you can use a String Dictionary Attribute or a Script Dictionary Attribute, so you don't need to use lots of 'ifs/switch-cases', too, though they're a bit more advanced than using/understanding List Attributes:

<object name="global_data_object">
  <attr name="color_stringdictionary_attribute" type="simplestringdictionary">red = redredredredredredredrredrredredrredrred; blue = bluebluebluebluebluebleublueblueblue; yellow = yellowyellowyeloowyellowyellowyellowyellowyellowyellow</attr>
</object>

<function name="color_function">
  show menu ("Color?", global_data_object.color_stringdictionary_attribute, false) {
    string_variable = StringDictionaryItem (global_data_object.color_stringdictionary_attribute, result)
    msg (string_variable)
  }
</function>

// output:
//
// (if chose/selected 'red'): redredredredredredredrdredrredred
// (if chose/selected 'blue'): blubelubleublueblueblueblueblue
// (if chose/selected 'yellow'): yellowyellowyellowyellowyellowyellowyellowyellow

// much shorter than using ifs/switch-cases, hehe


think of Dictionary (String Dictionary, Object Dictionary, Script Dictionary) Attributes as an 'input-output' or 'conversion' mechanism:

String Dictionary: string input ---> string output
Object Dictionary: string input ---> object output
Script Dictionary: string input ---> script(s) output

<attr name="whatever" type="simplestringdictionary">STRING_INPUT_1 = STRING_OUTPUT_1; STRING_INPUT_2 = STRING_OUTPUT_2; ETC</attr>

OR

<attr name="whatever" type="stringdictionary">
  <item>
     <key>STRING_INPUT_1</key>
     <value>STRING_OUTPUT_1</value>
  </item>
  <item>
     <key>STRING_INPUT_2</key>
     <value>STRING_OUTPUT_2</value>
  </item>
</attr>

StringDictionaryItem (NAME_OF_OBJECT.NAME_OF_STRINGDICTIONARY_ATTRIBUTE, STRING_INPUT) //  returns: STRING OUTPUT

// --------------------------------------------------------------

<attr name="whatever" type="simpleobjectdictionary">STRING_INPUT_1 = OBJECT_OUTPUT_1; STRING_INPUT_2 = OBJECT_OUTPUT_2; ETC</attr>

OR

<attr name="whatever" type="stringdictionary">
  <item>
     <key>STRING_INPUT_1</key>
     <value>OBJECT_OUTPUT_1</value>
  </item>
  <item>
     <key>STRING_INPUT_2</key>
     <value>OBJECT_OUTPUT_2</value>
  </item>
</attr>

ObjectDictionaryItem (NAME_OF_OBJECT.NAME_OF_OBJECTDICTIONARY_ATTRIBUTE, STRING_INPUT) //  returns: OBJECT OUTPUT

// note that the referenced/specified output objects, must actually exist, of course.

// --------------------------------------------------------------

<attr name="whatever" type="scriptdictionary">
  <item key="STRING_INPUT_1">
    msg ("SCRIPT_OUTPUT_1A")
    msg ("SCRIPT_OUTPUT_1B")
    msg ("SCRIPT_OUTPUT_1C")
  </item>
  <item key="STRING_INPUT_2">
    msg ("SCRIPT_OUTPUT_2A")
    msg ("SCRIPT_OUTPUT_2B")
    msg ("SCRIPT_OUTPUT_2C")
  </item>
</attr>

ScriptDictionaryItem (NAME_OF_OBJECT.NAME_OF_ScriptDICTIONARY_ATTRIBUTE, STRING_INPUT) //  returns: SCRIPT(S) OUTPUT