Learning ChoiceScript
- Part 1: Playing “My First ChoiceScript Game”
- Part 2: Choice, Finish, and Ending
- Part 3: Scenes
- Part 4: Using Variables
- Part 5: Text Formatting and Images
- Part 6: Fairmath
- Part 7: Inputs
- Part 8: Labels and Subrountines
- Part 9: Meta Commands
- Part 10: Customizing the Stat Screen
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.
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}.
The values of variables can included within the text of a project in this way.
Changing the Value of Variables
Similar to creating a variable, changing the value is possible through the *set command.
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.
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You didn't survive the trip! | |
(You made ${choices} choices!) | |
*ending |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
After a short delay, we enter the house. | |
(You made ${choices} choices!) | |
*ending |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*if choices > 1 | |
We've made many choices. | |
Finally, we arrived at the house. | |
Did we knock on the door or try to barge in without warning? | |
*choice | |
#Knock on the door | |
*set choices +1 | |
*goto_scene goodendings | |
#Barge in! | |
We got caught in a trap! | |
*goto_scene badendings | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*title Example | |
*author Dan Cox | |
*scene_list | |
startup | |
house | |
*create choices 0 | |
(You've currently made ${choices} choices.) | |
Where will we visit? | |
*choice | |
#The woods | |
We went into the woods! | |
It was a dark and scary place, but with our lantern, we were able to make our way deeper. | |
Deep in the woods, we came across a river. Did we try to cross it? | |
*set choices +1 | |
*choice | |
#Cross river | |
We did not make it across the river and were swept downstream to our doom! | |
*goto_scene badendings | |
#Did not cross river. | |
We didn't bother with the river and made our way along the path deeper and deeper into the woods. | |
*set choices +1 | |
*finish | |
#The mountains | |
We went into the mountains | |
*set choices +1 | |
*finish | |
#The lake | |
We went to the lake | |
*set choices +1 | |
*finish | |