Quillscript Variables

A variable is a named location in memory that holds a value.

To declare a Quillscript variable, type the desired name, and use the = (Assignment Operator) to assign a value.

$ my_variable = 10

Once assigned, you can use this data everywhere in your script and even in your Blueprint/C++ code.

$ name = Bob

- {name}
  Hello!
- {name}
  My name is {name}. 

Variable Type

Quillscript is an inferred type language, meaning that the variable type is automatically deduced. There are three variable types: Switch, Number, and Text. The variable type is used to determine the behavior of this variable for each operator, a Number type variable can be used for math operations, for example.

Switch

Represents an on/off state, also known as Boolean.

$ flag = on
$ state = off

Number

For numeric values. Integers and floating points.

$ number = 10
$ negative = -79
$ fraction = 4.88

Text

For string values.

$ word = hello
$ text = Hi! My name is Ed.

Variable Access

The variable mark describes how Quillscript interpreter handles its lifecycle and other automatized tasks.

Global

By default, any Quillscript variable is global. Once created, a global variable can be used in any other script, allowing script intercommunication.

Use global variables when persistence or intercommunication is necessary, and use temporary variables otherwise, since persistent variables take memory space, increase save file size, and increase the duration of certain tasks, like variable replacement in texts and expressions.

Temporary Variables

A Temporary Variable is a Quillscript variable that only exists during that script play. Temporary variables are automatically deleted when the script ends.

These variables are the preferred method for declaring variables when they don't need to exist after a script play. The use of these variables saves computing resources, since Quillscript has a smaller list of variables to search and apply tasks.

To declare a Temporary Variable, you name it starting with : (colons).

$ :greetings = on
$ :name = Doug

Outer Variables

Quillscript creates these variables to capture the return value of called functions. They have the same lifecycle of temporary variables and are deleted when the script ends. Check Function Call section for more details.

Template Variables

These variables are created by Quillscript to be used as arguments by a template call. They are deleted when a label statement is reached. Check Template section for more details.


Assigning Variables

Besides assigning static hard-coded values, variables also accept math expressions and other value concatenation methods.

Expressions

You can assign a complete math expression to a single variable, from a simple addition to a complex equation.

$ x = 10 + 5
$ y = ((2 + 2) * 4) ^ 2

It's possible to use other variable values in expressions. Notice the use of {} (brackets) to use a variable value instead of the literal string "value"

$ value = 5
$ result = {value} / 2

You can self-reference the assigned variable in an expression using a {&}.

$ value = 10
$ value = {&} + 5
// value equals 15

Or use a reduced assignment operation.

$ value += 10
$ value -= 10 + 2
$ value *= 5
$ value /= 5 - 6
$ value %= 2 * 2
$ value ^= 2

Valid Operators

or

Logical OR

Check if a or b is on

and

Logical AND

Check if a and b are on

==

Equal

Check if a equals b (case insensitive)

===

Strict Equal

Check if a equals b (case sensitive)

!=

NOT Equal

Check if a not equals b (case insensitive)

!==

Strict NOT Equal

Check if a not equals b (case sensitive)

<

Less

Check if a less than b

<=

Less Equal

Check if a less or equal b

>

Greater

Check if a greater than b

>=

Greater Equal

Check if a greater or equal b

+

Addition

Sum a plus b

-

Subtraction

Subtract b from a

*

Multiplication

Multiply a for b

/

Division

Divide a by b

%

Remainder

Find the remainder of a divided by b

^

Power

Power a by b

On Less, Less Equal, Greater, Greater Equal, Addition, Subtraction, Multiplication, Division, Remainder,and Power operations, it's required that the operands are numeric values. If a non-numeric value is passed, it is converted as follows:

  • on to 1

  • off to 0

  • A Text values is converted to numeric if possible, and to 0, otherwise.

Constructor

The operator constructor (:=) is used to assign a value to a variable only if that variable does not exist. This is useful for setup a script on its first play.

Complement the assignment (=) operator with the new (:) operator:

$ x := 1 + 1

This is the same as $ x = 1 + 1, but is executed only if there isn't already a variable called x.

Text Concatenation

The use of brackets allows the formation of texts by concatenation.

$ name = Dennis
$ surname = Ritchie
$ full_name = {name} {surname}

$ text = Hello Mr. {surname}.

Nested Variables Replacement

The use of brackets can also be done nesting a variable inside other variable brackets.

It is possible to use more elaborated replacement pattern if necessary

{{varName}}, {{var1}{var2}}, {text_{var}}, {{{var1}_text}_{var2}{var3}}, etc.

Constants

Constants work just like variables, they are assigned and handled the same way, but once created, they can't have their value changed.

Constants are declared on all uppercase.

$ CONST = 10
$ NAME = Alice
$ PI = 3.14

Deleting Variables

You should always remove variables that aren’t required to be permanently stored, as the more variables there are, the more time it takes to execute some tasks.

To delete a variable, call the built-in function Delete and pass the variable's name.

$ Delete name

Temporary variables are automatically deleted when the script ends, but you can delete them manually if needed.


Localizing Variables' Text

Although being stored as an Unreal Engin's Text type, Quillscript's Text variables are marked as cultural invariants by default. If the value of a variable must be localized, set its value inside `` (backticks)

$ response = `This text is localizable.`

Using Variables in Code

Quillscript variables are stored as an Unreal Engine Map of Name to Text. This map is declared in Quillscript Subsystem and is accessible in Blueprints and C++. Check Quillscript Static Library for detailed usage.


Variable Modifier

Check Register Variable Modifier and Unregister Variable Modifier

Under construction


Hard Coding Default Variables

Under construction

Last updated