Learning ChoiceScript: Part 4: Using Variables

Learning ChoiceScript

ChoiceScript is a scripting language from Choice of Games LLC for creating choose-you-own-adventure games.


 

Creating Variables

Like other scripting languages, ChoiceScript supports the the creation of variables. In ChoiceScript, to create a variable, use the command *create followed by the name of the variable and then its value.

Screenshot 2018-08-21 12.24.25

In ChoiceScript, variables are global. Once created they can be accessed in any file that is part of the project.

(For temporary variables, use *temp to create a value usable only within the file in which it was created.)

Using Variables

To show the value of a variables, enclose it in curly brackets and use a dollar sign. For example, when using a variable named “choices”, the code would look like the following: ${choices}.

Screenshot 2018-08-21 12.30.25

The values of variables can included within the text of a project in this way.

Screenshot 2018-08-21 12.31.37

Changing the Value of Variables

Similar to creating a variable, changing the value is possible through the *set command.

Screenshot 2018-08-21 12.34.41

Variables can be *set to new values and updated through using the operation and then the new value followed by the amount of value to change by. For example, to add one to a value, it would be “+1”. The same with subtracting by 10, “-10”.

Conditional Statements

The testing of values in ChoiceScript is also possible using the *if command.

Screenshot 2018-08-21 12.39.26

Possible Conditional Commands (copied from Important ChoiceScript Commands and Techniques):

  • Equal to: leadership = 40 (Is leadership equal to forty?)
  • Not equal to: leadership != 40 (Is leadership different from forty?)
  • Greater than: leadership >40 (Is leadership greater than forty?)
  • Less than: leadership <40 (Is leadership less than forty?)
  • Greater than OR equal to: leadership >=50 (Is leadership greater than or equal to fifty?)
  • Less than OR equal to: leadership <=40 (Is leadership less than or equal to forty?)
  • And: (leadership > 30) and (strength > 40)
  • Or: (leadership > 60) or (strength > 70)
  • Not: not(strength > 70)
  • Complex parentheses: ((leadership > 60) and (agility > 20)) or (strength > 80)

 

GitHub Gist Version: