Learning ChoiceScript: Part 8: Labels and Subrountines

Learning ChoiceScript

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


 

Labels

While the *goto_scene command can direct the player to another scene, there is other functionality that can reduce the dependence on using different files and help with better organizing code: labels.

Screenshot 2018-08-26 12.50.41

Using the *label command tells ChoiceScript to create a small section of code that can be visited like a sub-scene.

Screenshot 2018-08-26 12.51.32

Going to a scene is similar to using the command *goto_scene but references the scene and the label.

Label

 

Subroutines

Working like labels, subroutines are designed for doing a small, function-like task and then returning to the original place.

Screenshot 2018-08-26 13.01.43

Using the *label command, they are defined just like other labels but use the additional command *return.

Screenshot 2018-08-26 13.04.38

Subroutines are used through the *gosub command and then the name of the label.

Subs

GitHub Gist Version:

*title Example
*author Dan Cox
*scene_list
gate
*create password 15
*create trust 50
CHAPTER 1: THE JOURNEY BEGINS
[i]You may have heard of us…[/i]
I look up from the first page of the journal I had just written as my brother calls my name. "Jacob! Jacob! Stop wasting our ink. We still have many miles to travel and I can't have you wasting supplies!"
"Yes, William," I reply, glancing at the top of the page where I have carefully written our names before closing the journal and carefully putting it away.
[i]The Brothers Grimm[/i]
He nodded as the journal disappeared into my bag. "Good. Now that I have your attention. [b]Do you remember where father told us to look next?[/b]"
I looked around and considered my options.
*choice
#The woods?
*image woods.jpg
William paused for a moment to think back to the conversation we had with our father before we set out. "Yes," he finally replied, nodding to himself. "We were told to go into the woods next."
*set trust %+20
*gosub writing
*goto_scene startup house
*finish
#The mountains?
William paused for a moment to think back to the conversation we had with our father before we set out. "No," he finally replied, frowning at me. "We were told to go into the woods next."
*set trust %-20
*gosub writing
*goto_scene startup house
*finish
#The lake?
William paused for a moment to think back to the conversation we had with our father before we set out. "No," he finally replied, frowning at me. "We were told to go into the woods next."
*set trust %-20
*gosub writing
*goto_scene startup house
*finish
*label house
Finally, we arrived at the house.
[b]Did we knock on the door or try to barge in without warning?[/b]
*choice
#Knock on the door
*goto_scene goodendings
#Barge in!
We got caught in a trap!
*goto_scene badendings
*label writing
I took notes on our surroundings.
*return

view raw
startup.txt
hosted with ❤ by GitHub