FANDOM


    The *temp command is used to create a temporary variable, as opposed to a permanent variable defined in startup.txt using the *create command.

To better understand the main differences between these two types of variables, read the article on variable types.

Temporary variables

As with permanent variables, a temporary variable can also be any one of the three different data types, either numeric (containing a number), a string (containing "text"), or a boolean (either true or false).

In all three cases a new temporary variable is created in the exact same way, simply by assigning it a new and unique name and a default starting value:

*temp var false

In the above example we have effectively created a new temporary variable named var and have assigned a default starting value of false, making it a boolean variable type. We could instead have assigned a number

*temp var 0

making it a numeric variable, or "some text" to make it a string variable:

*temp var "Alex"

In all cases the *set command may then be used - within the same scene file - to modify the initial default value, or we could perhaps make use of it for conditional *if / *else statements. Also, with the *rand command we could immediately after randomize the initial value of any numeric temporary variable.

Temporary Variables really are Temporary!

The most important thing to bear in mind concerning *temp variables is that they are exactly that -- temporary. As soon as your game loads a new scene file as a result of either a *finish or *goto_scene command, all of your temporary variables -- and their values -- are lost from memory. In essence, temporary variables can only be used within the current scene file.

While you can of course create new *temp variables of the same name in the next scene file, those would count as brand new variables and all previously-held values would still have been lost. Where this may cause some continuity problems in either your story or your scripting, those particular variables should instead be defined in startup.txt as permanent variables, using the *create command.

Where & when to use temporary variables

Temporary variables are specifically intended to carry short-term information, and for virtually any purpose. They are typically used to carry conditional data for later use in such as *if, *selectable_if, and perhaps *hide_reuse conditions: if the player met Colonel Mustard; if the player kissed Miss Scarlett; if the player visited the library; if the player saw the bloodstained candlestick . . . or indeed everything and anything that you might need to record for only a short period of time in order to determine how -- or indeed, if at all -- that recent event will impact something else in the near future.

Error: "Non-existent variable [name]"

As discussed in the Wiki article Basic Scene Scripting, "non-existent variable" errors are all too common when first learning ChoiceScript, as it can at first be difficult to grasp the logic behind what precisely causes such an error to occur.

If not a simple misspelling of the variable name (a single letter wrong - or missing - is all it takes) the cause is almost always due to where the *temp command actually appears in your scripting, as explained in the Basic Scene Scripting article.

The simplest solution, and the easiest way of avoiding many such errors, is to always list all *temp commands at the very top of each scene file in which they are intended to be used, with a default starting value appropriate to that data type, and which you would simply *set accordingly later in your story scripting to suit. Examples of default starting values placed at the start of each scene file would be:

*temp var1 0  [a numeric default value of zero]

*temp var2 ""  [a blank string value using double quotes with no content]

*temp var3 false  [a default boolean, which must always be either true or false]

By this means, the variable itself would always exist throughout that scene file and "non-existent variable" type errors will occur far less often.


More commands
Choice *choice, *fake_choice, *disable_reuse, *hide_reuse, *allow_reuse, *selectable_if
Variable *create, *temp, *set, Arithmetic operators, *delete, *input_number, *input_text, *print, *rand
Conditional *if, *elseif, *else
Goto *label, *goto, *goto_scene, *goto_random_scene, *gosub, *gosub_scene, *finish
Formatting Bold text, Italic text, *image, *line_break, *page_break, *link, *stat_chart
Miscellaneous *comment, *scene_list, *title, *author, *achieve, *achievement, *check_achievements, *bug, *ending, *more_games, *share_this_game, *show_password, *script

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.