Global/story-wide variables


Okay, I’m going to quote from this page for my question, since it pretty much sums up the effect I want to pull off in my own game.

How will you handle this?
#Try to talk them out of it.
------They cannot be dissuaded.
#Force them to relent.
------They back down, for now.
—*if (president) #Abuse my presidential powers to silence them
------This works; you will never hear from them again.

How and where do you define something like “president”? I’m assuming it’s in the mygame.js file along with the other global/permanent variables. But why is it “*if (president) #Etc” and not “*if (profession = president) #Etc”?

I’ve seen the one-word global variable used in script in various other places around the site, wiki, and forum, but I can’t figure out how to set it up or define it in a file.

Is it like this example from the mygame.js wiki page?

stats = {

—look: “Nice Appearance”

—,strength: 50

—,exam_passed: true

—,princess_met: false

So instead of look: “Nice Appearance” you would say something like profession: “Undefined”
then in a beginning scene you would write a line like
*set profession president
and then later in the story you could use
*if (president) #Etc ?

Is that enough? Is that how you set that sort of thing up or am I missing something?

Thanks for your help!

~little coder that could


The president variable in the example is a boolean. Which is either true or false. When a variable is first assigned either of these values it falls under this category. The default would be true in CS. Hence you can just put *if (president) which has the same result to *if (president=true)


If you wish to go the string route:

*set profession "president"

Then later on:
*if (profession="president") #yourchoicegoeshere

And yes, global variables are declared in mygame.js since the *create command is phasing out. Hope that helps.


@littlecoder There are two pages on the wiki worth taking the time to study once you get into the whole ‘variables’ thing.

The first explains the main differences between the two types of variables (temporary ones created in your scripting, and permanent, global ones defined in mygame.js):

And the second discusses the three types of information (numeric, string or boolean) a variable of either type can hold, and the differences between those data types:


Some languages will even let you write: if(!president) which means if it’s not true but null or false.
I’m not sure choice script allows that short hand method though.


Oooh. I get it now. Thanks everyone! That helps a ton.


@CJW, “if not(president)” works with ChoiceScript. Don’t know if you can swap ! for not…


Thanks for clearing that up. I wouldn’t have thought you could swap it in that case, each language is different, raw js uses the ‘!’.