• With over 20,000 games created, The most widely used novel game engine.

What Are Variables?

In TyranoScript, you can use variables.

A variable is essentially a container that stores something.
That "something" can be, for example:

・The protagonist’s name entered by the player
・A character's affection level
・Flag management

These are just a few examples. The phrase "a flag is raised" has become fairly common in games and storytelling.

■Types of Variables

TyranoScript allows you to use the following three types of variables:

  • System Variables
    Variables shared across the entire game. For example, you can use them to store values not affected by save data, such as "whether the ending has already been viewed."
  • Game Variables
    Variables managed for each save file. They are overwritten when another save file is loaded. For example, these can be used to store game progress-related data like "item management" or "which choice was selected."
  • Temporary Variables
    Variables used for temporary data. These are not restored when the game is resumed.

Let’s take a look at some actual code:


;Assign a number to a game variable
[eval exp="f.flag1 = 1000"]

;Assign a string to a system variable
[eval exp="sf.variable1 = 'string'"]

;Assign a value to a temporary variable
[eval exp="tf.flag1 = f.flag2"]


The values assigned this way can be used later in conditional branches, displayed directly on the screen, and more.

Furthermore, by using the [iscript] tag, you can write multiple eval statements more concisely. For example, the previous code can be written as:

[iscript]

f.flag1 = 1000
sf.variable1 = 'string'
tf.flag1 = f.flag2
[endscript]


Both versions perform exactly the same actions.



Allowed Variable Names

In TyranoScript, you can freely assign names to variables. However, please follow the rules below:

・Variable names can include alphanumeric characters, full-width characters, and underscores (_).
(Example) f.flag_test, sf.your_name_3

・Variable names cannot start with a number.
(Example) × f.3name is not allowed



Variable Operations

If you want to perform calculations:


[eval exp="f.flag1 = f.flag1 + 1"]

In this example, the value of f.flag1 is increased by 1 and stored back into f.flag1 (in other words, it adds 1 to f.flag1).


[eval exp="f.flag1 = f.flag1 + f.flag2 * f.flag3"]
The result of f.flag2 multiplied by f.flag3 is added to f.flag1 and stored in f.flag1.
Use a slash ( / ) for division.

You can also concatenate strings using +

[eval exp="f.flag2 = 'hoge'"]
[eval exp="f.flag3 = 'une'"]
[eval exp="f.flag1= f.flag2 + f.flag3"]



Deleting Variables

To delete a variable, use `delete variable_name`. For example, to delete `f.flag1`, write:


[iscript] 
delete f.flag1;
[endscript]


That’s how you write it.

You can delete all game variables at once with the [clearvar] tag.
Use the [clearsysvar] tag to delete all system variables.



Displaying Variable Values

If you want to display the value of a variable in your scenario, use the [emb] tag.
For example:


[cm]
[eval exp="f.num=200"]
[eval exp="f.mojiretu='Hello there'"]

Contents of f.num : [emb exp="f.num"][l][r]
Contents of f.mojiretu : [emb exp="f.mojiretu"][l][r]


The output will be:
Contents of f.num: 200
Contents of f.mojiretu: Hello there

This is useful, for example, when allowing the player to choose the protagonist’s name.



Entity

The entity feature allows you to substitute variable values into other tag attributes.
To do this, prefix the variable name with an `&` symbol within the attribute value.


;Assign text to a temporary variable
[iscript]
tf.title = "This is a test"
[endscript]
;Use the assigned variable as the value for the text attribute — "This is a test" will be displayed on screen
[ptext layer=1 page=fore text=&tf.title size=30 x=180 y=150 color=red ]