Creating variables

When declaring variables, is it required for the variable to be declared at the top of the startup file? Or am I able to declare them throughout the file as long as I create them before they’re used?

All variables need to have a value when created. this value can be zero (0) or nothing at all using this format:

*create variable1 ""

Which will result in a “blank” variable. This has to be done in the startup file. The variable can then be modified later on using:

*set variable1 [your value here]

Screenshot

No, it’s not. Here’s a screenshot of my startup file from a game of mine that’s in hiatus. All these variables are beneath the scene list.

As long as the variable is somewhere in the startup file, and listed as a variable command, it’s viable. Temp variables can be created elsewhere/other scene files IIRC, but are temporary. As in, they only last within the scene file they are created.

3 Likes

Thanks. Just wanted to make sure I didn’t have to create a bunch of variables at the top of I wasn’t going to need them until chapter 3.

So… after a bit of testing the actual commands you can or can’t use before *create is weird. But bottom line, you can’t use *create outside of the startup file and you can’t use it after labels, choices, or conditionals.

Essentially, all your variable declarations do need to be at the top-ish of the startup file.

You can edit your startup file anytime though, so you don’t have to worry about declaring everything all at once. When you need new variables, you can just go back to the startup file and add them.

3 Likes
  • Global variables: variables used throughout the game. They must be declared in the startup file. Use the *create command. They should be declared after *scene_list and before anything else.

  • Local variables: used inside a scene only. As soon as you leave a scene, these variables are lost. You can declare them anywhere in the scene file as long as the CS Engine has processed them before they are used. Since the CS Engine, by nature, jumps a lot from label to label inside the file, it is a good practice to declare all variables at the beginning of the file. Use the *temp command.

Hope this helps.

3 Likes

*create command must be declared in your startup.txt, below the *scene_list, above the *achievement (if any). This is your global variables and their value persists the entire playthrough.

*temp command can be declared anywhere (even in the startup.txt). However, their value persists only for a scene file and will be purged upon *finish or *goto_scene command, so care need to be taken.


For the best practice, I’d recommend to put all of your variables as *create, though. And then move them into relevant scenes with *temp command where they’re used. At least this saves your butt if you, unintentionally, have the same variable cross-scenes or forgot that there’re duplicates.

I’m pretty new so may be what I’m doing will look green, I have variables - also in savegame files,
I have variables used as checkpoints, level designaters & measurement agents.

Also I use temp variables just for that scene to have random outcomes and than forget about them.

I do not save those for checkpoints its like meet_Joe_Black false - once it’s set true in the story you do not need value for that.
For level designaters or measurement agents I just set 0

etc:

startup.txt
*create meet_Joe_Black false
*create basic 0
*create medium 0
*create hard 0

and also add them to variables.txt
*set meet_Joe_Black “”
*set basic 0
*set medium 0
*set hard 0

now your.scene.txt
so when in your appropriate part of the scene you say;

*temp bsctraining
*random bsctraining 1 4
*temp mdmtraining
*random mdm training 5 8
*temp hrdtraining
*random hrdtraining 9 12

*set meet_Joe_Black true
*if (meet_Joe_Black)
*choice
#train with Joe Black in the morning
*set basic +1
#train with Joe Black half day
*set medium +1
#train with Joe Black all day.
*set hard +1

*well you can add ‘Joe_Black’ variable if you are going to have a relationship status with that character .

so later when I want to think about assesment of the day and add some stat skills or just observe

*if basic > 1
you gained strength ${bsctraining}

  • set strength + % bsctraining

*if medium > 1
you gained strength ${mdmtraining}

  • set strength + % mdmtraining

*if hard > 1
you gained strength ${hrdtraining}
*set strength + % hrdtraining

this is a sloppy example and I’m also a freshman here but this worked smoothly so far.
Keeps savegame file free of unnecessary itesm as well as your stats.

basic, medium and hard will be reusable on next scene, with reset values (not saved)
temp variable training is gone after serving with honor ^^

temps are pretty usefull so read about them in the choicegames.com guide or at the wiki.

Have a nice day

Just a quick correction: You can’t do this. Your variables cannot be both a string and a boolean. If you’re using this method, make sure they’re consistent or you’ll get errors.

Well had to add some checkpoint or level variables to avoid temp variable problems.
(If values needed for next scenes also in savegame.txt as well besides variables and startup)
So temp variables adding value to variable to prevent confusion.
Probably it is why it didn’t work , trying to use different rand value malfunctioned the script.

It didn’t work because you created the variable as a boolean and then used *set to modify the variable as if it were a string variable.

To add, while you can’t do

*create boolean_var false
*set boolean_var "text"

you’re perfectly fine to do

*temp boolean_var false
*set boolean_var "I proclaim thee as text thing"
2 Likes

Self answer for the record: Seems possible if keep booelans and string variables clean and neatly listed.

I have a question , I’m so so ready for first playable demo but I want to complete more scenes and also a main action theme so it will give the taste of the game.

My WIP based on sports / competition so I have squad.
For each squad member have to attain more or less 10 variables

*create no1 0
*create no1name “”
*create no1age 0
*create no1value 0
*create no1status 0

*create no1strength 0
*create no1condition 0
*create no1mability 0
*create no1plyability 0
*create no1speed 0

for each squad member in rooster will put it like no2 no3 and so on and so on.

Also added gpa variables and for each and squadtotal variables (I will use this to get gpa for each)
so for squad more or less 12 variables
and for each member in rooster 10 variables .

More than 100 variables for squad issues .
Will this create a confusion for game arithmerics?

choices will result with different events and each of them will provide different points to variables , some more some less etc.

For eg MC managed funds to increase team gear - it will create training bonus etc.
or coach and MC made a meeting and provided items he requested - if doable by MC at that level certain point bonuses for trainings etc.