How do I make a player choose from certain number of options?

karinchan999
13 Oct 2016, 13:15

Like how do they choose their own gender (there's only two options and if they type anything else, it's not valid). Or if they choose their own class (like warrior, mage, etc.).

Can anyone please help me? Thank you in advanced!


The Pixie
13 Oct 2016, 13:32

The best way is through a menu. I am going to do this in code because it is easier to show here. Click on the Code view button, and paste the code into your game, and then go back to normal GUI view, and then edit to suit your needs.

list = Split("warrior;mage;thief;scientist", ";"
ShowMenu("Select a character class", list, false) {
  player.class = result
  msg("You are a " + result)
}

The first line sets up all the options, the second line shows the menu. Whatever the player selects goes inside a magic variable called result, and that is used to set an attribute of the player and to print a message.

This is all inside a nested script, note how the lines are indented. They will still be indented in the GUI view, and you need to make sure any other commands are the same (otherwise they will run when the menu is first shown, rather than when the player makes a choice).


karinchan999
13 Oct 2016, 13:46

I did as you said and copied the code but this showed up when I tested the game

"Failed to load game.
The following errors occurred:
Error: Error adding script attribute 'script' to element 'C1 Page9 2': Function not found: 'ShowMenu'"

What do I do?


The Pixie
13 Oct 2016, 14:33

Are you doing a game book? I was assuming a text adventure, and I am not sure what you can do in a game book.

Well, one option is to just have links on the page to each option; one page links to wizard, one to monk, etc.


hegemonkhan
13 Oct 2016, 20:31

a method is to create your own menu, if using Game Book:

1. first, create/add a String List Attribute, which will hold your menu choices:

'NAME_OF_YOUR_FIRST_PAGE' Page Object -> 'Page' Tab -> Page Type: [script] or [script+text] -> (see below)

add new script -> 'Variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable NAME_OF_YOUR_FIRST_PAGE.NAME_OF_YOUR_STRING_LIST_ATTRIBUTE = [EXPRESSION] split ("NAME_OF_OPTION/CHOICE_1; NAME_OF_OPTION/CHOICE_2; NAME_OF_OPTION/CHOICE_3 ; ETC ETC ETC", ";")

2. next, we also need to create/add those in-game-character-attributes Attributes:

'NAME_OF_YOUR_FIRST_PAGE' Page Object -> 'Page' Tab -> Page Type: [script] or [script+text] -> (see below)

add new script -> 'Variables' section/category -> 'set a variable or attribute' Script -> (see below)

(the Game Book only has two Objects which you can add/create Attributes within: the 'player' Player Object and the 'game' Game Object)

set variable player.NAME_OF_YOUR_CHARACTER_ATTRIBUTE = [EXPRESSION] YOUR_VALUE_OR_EXPRESSION
~OR~
set variable game.NAME_OF_YOUR_CHARACTER_ATTRIBUTE = [EXPRESSION] YOUR_VALUE_OR_EXPRESSION

for an example:

(I like using descriptive labels/names and the underscore, and hate using capitol letters, but you can name/label stuff however you want, within what's allowed. Also, the names must be unique, as the name is the ID of things for quest)

set variable player.sex = [EXPRESSION] "unknown" // not using my own convention/system of descriptive names
~OR~
set variable player.sex_string_attribute = [EXPRESSION] "unknown" // me, using my convention/system of descriptive names
~OR~
set variable game.sex = [EXPRESSION] "unknown" // not using my own convention/system of descriptive names
~OR~
set variable game.sex_string_attribute = [EXPRESSION] "unknown"

// hopefully, you get the idea/understand now about naming/labeling, vs my own personal naming/labeling system/convention

set variable player.race = [EXPRESSION] "unknown"
~OR~
set variable game.race = [EXPRESSION] "unknown"

set variable player.class = [EXPRESSION] "unknown"
~OR~
set variable game.class = [EXPRESSION] "unknown"

// for these specific types of in-game-attributes (sex, class, race, etc), they're String Attributes, and thus we must have/make them be, indeed, String Attributes, which we're able to do via having our Value be encased within double quotes. You don't have to have my use of 'unknown', you could just have an empty String Value:
//
// set variable player.class = [EXPRESSION] ""
//
// as, the value doesn't matter, as it's just a default/initial value, which should be getting changed right away by the 'character creation', at least usually is done so, in most games. The double quotes (2 of them) ARE required, however. 

if you want to set/create/add other types of Attributes, then you wouldn't use the double quotes, for examples:

set variable player.strength_integer_attribute = [EXPRESSION] 0
set variable game.is_dragon_dead_boolean_attribute = [EXPRESSION] false

3. now, we can finally do/create our custom menu creation/scripting:

Functions -> Add -> Name: 'whatever you want to call/name/label it as' -> (see below)

add new script -> 'Variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable i = [EXPRESSION] 0 // 'i' is often used for your 'iterator/counting' Variable, but you can call/name/label the Variable as whatever you want.

add new script -> 'Output' section/category -> 'print a message' Script -> (see below, for an example using class)

print [EXPRESSION] "Select your Class (type in the number):"

// I don't know what GUI~Editor's script options for this stuff directly below (as I don't know the Text Adventure's GUI~Editor that well, and especially not the Game Book and its GUI~Editor), so I'm going to show it in code (hopefully you can figure out how to do this in the GUI~Editor's 'add new script' options):

// you can re-name my use of 'menu_option_variable' to whatever you want.

foreach (menu_option_variable, game.NAME_OF_YOUR_MENU_LIST_1) {
~OR~
foreach (menu_option_variable, player.NAME_OF_YOUR_MENU_LIST_1) {

-> add new script -> 'Variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable i = [EXPRESSION] i + 1

-> add new script -> 'Output' section/category -> 'print a message' Script -> (see below)

print [EXPRESSION] i + ". " + menu_option_variable
// this will output, for an example using class:
// 1. warrior
// 2. thief
// 3. cleric
// 4. wizard

} // end of 'foreach' Function/Script

4. next, we need to allow and get the user's input/choice/selection, and then check it and set it to the Attribute (or if wrong input, re-do/run the menu choice):

add new script -> 'Output' section/category -> 'get input' Script

-> add new script -> 'Scripts' section/category -> 'if' Script -> (see below)

if [EXPRESSION] IsInt (result) and result > 0 and result <= ListCount (game.NAME_OF_YOUR_MENU_LIST_1)
~OR~
if [EXPRESSION] IsInt (result) and result > 0 and result <= ListCount (player.NAME_OF_YOUR_MENU_LIST_1)

->-> add new script -> 'Variables' section/category -> 'set a variable or attribute' Script -> (see below)

set variable player.NAME_OF_YOUR_ATTRIBUTE = [EXPRESSION] StringListItem (game.NAME_OF_YOUR_MENU_LIST_1, ToInt (result) - 1)
~OR~
set variable player.NAME_OF_YOUR_ATTRIBUTE = [EXPRESSION] StringListItem (player.NAME_OF_YOUR_MENU_LIST_1, ToInt (result) - 1)
~OR~
set variable game.NAME_OF_YOUR_ATTRIBUTE = [EXPRESSION] StringListItem (game.NAME_OF_YOUR_MENU_LIST_1, ToInt (result) - 1)
~OR~
set variable game.NAME_OF_YOUR_ATTRIBUTE = [EXPRESSION] StringListItem (player.NAME_OF_YOUR_MENU_LIST_1, ToInt (result) - 1)

-> else,

->-> ClearScreen // in code (not sure how this is done with the GUI~editor)

->-> add new script -> 'whatever it is, ?Scripts?' section/category -> 'call function' Script -> type in the: NAME_OF_YOUR_FUNCTION // this re-does/re-runs the function if you gave it the wrong input (not a number or a number that is not within the number choice range)

// end of 'else'

in code (using Text Adventure --- I'm familiar with it, so it'll be faster for me), example:

(hopefully no errors... and hopefully you can translate/convert from this Text Adventure example to how it's done in the Game Book)

<asl version="550">

  <include ref="English.aslx" />
  <include ref="Core.aslx" />

  <game name="example">

    <gameid>xxx</gameid>
    <version>1.0</version>
    <firstpublished>2016</firstpublished>

    <attr name="class_stringlist_attribute" type="simplestringlist">warrior;thief;cleric;wizard</attr>

    <attr name="start" type="script">
      class_character_creation_function
    </attr>

  </game>

  <object name="room">

    <inherit name="editor_room" />

    <object name="player">

      <inherit name="editor_object" />
      <inherit name="editor_player" />

      <attr name="class_string_attribute" type="string">unknown</attr>

    </object>

  </object>

  <function name="class_character_creation_function">
    msg ("Class?")
    msg ("") // just for line spacing (easier for person playing game, to read it)
    i = 0
    foreach (menu_option_variable, game.class_stringlist_attribute) {
      i = i + 1
      msg (i + ". " + menu_option_variable)
    }
    msg ("") // just for line spacing (easier for person playing game, to read it)
    get input {
      if (IsInt (result) and ToInt (result) > 0 and ToInt (result) < ListCount (game.class_stringlist_attribute)) {
        player.class_string_attribute = StringListitem (game.class_stringlist_attribute, ToInt (result) - 1)
        ClearScreen
      } else {
        ClearScreen
        class_character_creation_function
      }
    }
  </function>

</asl>