Game variables are used to store information in a running game. This information could be anything – usually the player’s progress in the game (like status of quests or solved puzzles). But that’s not all, you can even create whole new systems using variables (like a calendar system).

A game variable consists of two parts:

  • Variable key
    The key (or name) of the variable is used to identify it.
    Please note that variable keys can’t have an empty space!
    E.g. ‘Final Quest’ isn’t allowed, use ‘Final_Quest’ instead.
  • Variable value
    The value stores the information assigned to the variable key.

Game variables are saved in save games – you can change if (and which) variables will be saved in Menus > Save Game Menu.

There are different types of game variables:

  • Local
    Local game variables are only available in the event system, formulas and battle AIs.
    As soon as the event/formula/battle AI has finished, the variable will be gone.
    Usually you’d use them to keep track of something that’s only needed within an event, formula or battle AI.
    Formulas called by an event/battle AI or another formula (directly or through an underlying battle action) will share the local variables with it.
  • Global
    Global game variables are available everywhere and any time.
    They’ll be saved with a save game and are persistent throughout the game.
  • Object
    Object game variables are bound to game objects in your scene using an Object ID.
    You can use them to store information on objects, like keeping track how often you talked to an NPC.
    They’ll also be saved with a save game and are persistent throughout the game.
    Object game variables require an already existing game object with an Object Variables component attached to access them.
  • Ability/Item/Equipment
    Instances of abilities, items or equipment can have game variables attached to them.
    They’re accessible through the Selected variable origin in events, formulas and battle AI, when they where previously set as Selected Data.
    You can learn more about selected data in this how-to.
    These variables will also be saved with save games (if the instances of the abilities, items and equipment are saved, e.g. with the player combatant’s abilities/inventory).

Values

A game variable can store the following types of values:

  • string (Text)
  • bool (Trigger)
  • float (Number)
  • Vector3 (Position)

Each variable key can hold one value of each type. If you store another value of the same type into a variable, the old value will be lost.

String values

String values can store all kind of information – a string is simply a text. You can use them to remember the name of a scene, change a combatant’s name and many other things.

When creating complex quests, it can be useful to store some information in a string variable and display or check it at a later time.

Example Value
Quest Finished

Bool values

Bool values are simple triggers. You can use them to simply store that something happened, like an event that has been performed.

Example Value
true

Float values

Float values can be used for complex operations – a float is a number and allows using decimal numbers. You can use them in formulas or even change them using mathematical operations.

When building complex systems (like a calendar), this is what you’ll most likely use.

Example Value
5.3

Vector3 values

Vector3 values can be used to store positions. They can be used in events or scene targets to spawn or move game objects at those positions.

Example Value
X=3, Y=4, Z=0

Setting game variables

Game variables can be changed by multiple things, e.g. the event system, using an item or defeating an enemy.

The settings for changing game variables are always the same. Depending on which type of variable you want to change, the settings differ a bit – but some base settings are still valid for all game variable types.

Variable Key

Value Type

Defines where the key (name) of the game variable comes from:

  • Value
    The text defined in Text is the key (name) of the variable.
  • Game Variable
    Text is the key of a game variable (string) which holds the key of the variable that will be changed.
  • Player Prefs
    Text is the key of a PlayerPrefs (string) variable which holds the key of the variable that will be changed.
    See the Unity® documentation for details on PlayerPrefs.
  • Scene Name
    The name of the current scene.

Remove

The game variable will be removed. This will remove all values assigned to the variable key.
If disabled, the variable will be changed/set.

Type

Select the type of the value that will be changed:

  • String
    A string value will be changed.
  • Bool
    A bool value will be changed.
  • Float
    A float value will be changed.
  • Vector3
    A Vector3 value will be changed.

Depending on the type selection you’ll have different settings for defining the value.

String value

howto_game_variables1

Value Type

Defines where the value the game variable (string) will be changed to comes from:

  • Value
    The text defined in Text is the value that will be used.
  • Game Variable
    Text is the key of a game variable (string) which holds the value that will be used.
  • Player Prefs
    Text is the key of a PlayerPrefs (string) variable which holds the value that will be used.
    See the Unity® documentation for details on PlayerPrefs.
  • Scene Name
    The name of the current scene is used as value.

Bool value

howto_game_variables2

Value

The game variable (bool) will be set to the value defined here (either true or false).

Float value

howto_game_variables3

Operator

Select the operator that will be used to change the game variable (float):

  • Add
    Adds the value to the current value of the variable.
  • Sub
    Subtracts the value from the current value of the variable.
  • Multiply
    Multiplies the current value of the variable with the value.
  • Divide
    Divides the current value of the variable by the value.
  • Modulo
    Uses the modulo operator, current value of the variable % the value.
  • Power Of
    The current variable value to the power of the value.
  • Log
    The current variable value is used in a logarithmic calculation with the value as base.
  • Set
    Sets the current variable value to the value.

Value Type

Defines where the value the game variable (float) will be changed with comes from:

  • Value
    The number defined in Value will be used.
  • Game Variable
    Variable Key is the key of a game variable (float) which holds the value that will be used.
  • Player Prefs
    Variable Key is the key of a PlayerPrefs which holds the value that will be used.
    Is Int defines if an int or float PlayerPrefs will be used.
  • Formula
    The result of the formula selected in Formula is used as value.
    The formula uses the player combatant as user and target.

Rounding

All Value Type settings except Value provide a rounding option:

  • None
    No rounding will be performed.
  • Ceil
    The value will be rounded up (e.g. 10.2 will become 11).
  • Floor
    The value will be rounded down (e.g. 8.9 will become 8).
  • Round
    The value will be rounded normally (e.g. 5.4 will become 5, 8.7 will become 9).

Vector3 value

howto_game_variables4

Value Type

Defines where the value the game variable (Vector3) will be changed to comes from:

  • Value
    The Vector3 defined in Value will be used.
  • Game Variable
    Variable Key is the key of a game variable (Vector3) which holds the value that will be used.
  • Scene Position
    The scene position of the current scene (or (0,0,0) if not set).
    You can set a scene positions in the event system.
  • Player Position
    The current position of the player.

Checking game variables

Game variables can be checked on multiple locations in ORK Framework, e.g. the event system or requirements.

The settings for checking game variables are always the same. Depending on which type of variable you want to check, the settings differ a bit – but some base settings are still valid for all game variable types.

Variable Key

Value Type

Defines where the key (name) of the game variable comes from:

  • Value
    The text defined in Text is the key (name) of the variable.
  • Game Variable
    Text is the key of a game variable (string) which holds the key of the variable that will be checked.
  • Player Prefs
    Text is the key of a PlayerPrefs (string) variable which holds the key of the variable that will be checked.
    See the Unity® documentation for details on PlayerPrefs.
  • Scene Name
    The name of the current scene.

Is Valid

If enabled, the result of the check must be valid

If disabled, the result of the the check must be invalid.

Type

Select the type of the value that will be checked:

  • String
    A string value will be checked.
  • Bool
    A bool value will be checked.
  • Float
    A float value will be checked.
  • Vector3
    A Vector3 value will be checked.

Depending on the type selection you’ll have different settings for defining the value that will be checked.

String value

howto_game_variables5

Value Type

Defines where the value the game variable (string) will be checked for comes from:

  • Value
    The text defined in Text is the value that will be used.
  • Game Variable
    Text is the key of a game variable (string) which holds the value that will be used.
  • Player Prefs
    Text is the key of a PlayerPrefs (string) variable which holds the value that will be used.
    See the Unity® documentation for details on PlayerPrefs.
  • Scene Name
    The name of the current scene is used as value.

Bool value

howto_game_variables6

Checking a game variable (bool) doesn’t require any other settings, the Is Valid setting defines if the value of the variable is checked for true or false.

Float Value

howto_game_variables7

Check Type

Select when the check will be valid:

  • Is Equal
    The current value of the game variable (float)  is equal to the defined value.
  • Is Less
    The current value is less than the defined value.
  • Is Greater
    The current value is greater than the defined value.

Value Type

Defines where the value the game variable (float) will be checked with comes from:

  • Value
    The number defined in Value will be used.
  • Game Variable
    Variable Key is the key of a game variable (float) which holds the value that will be used.
  • Player Prefs
    Variable Key is the key of a PlayerPrefs which holds the value that will be used.
    Is Int defines if an int or float PlayerPrefs will be used.
  • Formula
    The result of the formula selected in Formula is used as value.
    The formula uses the player combatant as user and target.

Rounding

All Value Type settings except Value provide a rounding option:

  • None
    No rounding will be performed.
  • Ceil
    The value will be rounded up (e.g. 10.2 will become 11).
  • Floor
    The value will be rounded down (e.g. 8.9 will become 8).
  • Round
    The value will be rounded normally (e.g. 5.4 will become 5, 8.7 will become 9).

Vector3 value

howto_game_variables8

Check Type

Select when the check will be valid:

  • Is Equal
    The distance between the current value of the game variable (Vector3)  and the defined Value (Vector3) is equal to the defined distance.
  • Is Less
    The distance is less than the defined distance.
  • Is Greater
    The distance is greater than the defined distance.

Distance

The distance that will be used for the check.

The distance between the current value of the game variable (Vector3) and the defined value (Vector3) will be checked against this distance.

Value Type

Defines where the value the game variable (Vector3) will be checked with comes from:

  • Value
    The Vector3 defined in Value will be used.
  • Game Variable
    Variable Key is the key of a game variable (Vector3) which holds the value that will be used.
  • Scene Position
    The scene position of the current scene (or (0,0,0) if not set).
    You can set a scene positions in the event system.
  • Player Position
    The current position of the player.

Code access

You can also change and check game variables via code.

Getting variables

ORK.Game.Variables.GetString(string key)
Returns the value of the game variable (string) key.

ORK.Game.Variables.GetBool(string key)
Returns the value of the game variable (bool) key.

ORK.Game.Variables.GetFloat(string key)
Returns the value of the game variable (float) key.

ORK.Game.Variables.GetVector3(string key)
Returns the value of the game variable (Vector3) key.

Changing variables

ORK.Game.Variables.Remove(string key)
Removes all values of the game variable key.

ORK.Game.Variables.Set(string key, string value)
Sets the game variable (string) key to value.

ORK.Game.Variables.Set(string key, bool value)
Sets the game variable (bool) key to value.

ORK.Game.Variables.Set(string key, float value)
Sets the game variable (float) key to value.

ORK.Game.Variables.Set(string key, Vector3 value)
Sets the game variable (Vector3) key to value.

ORK.Game.Variables.ChangeFloat(string key, float value, FormulaOperator op)
Changes the game variable (float) key by value, using the operator op.
FormulaOperator is an enumeration and offers the following options:

  • FormulaOperator.Add
    Adds the value to the current value of the variable.
  • FormulaOperator.Sub
    Subtracts the value from the current value of the variable.
  • FormulaOperator.Multiply
    Multiplies the current value of the variable with the value.
  • FormulaOperator.Divide
    Divides the current value of the variable by the value.
  • FormulaOperator.Modulo
    Uses the modulo operator, current value of the variable % the value.
  • FormulaOperator.Power Of
    The current variable value to the power of the value.
  • FormulaOperator.Log
    The current variable value is used in a logarithmic calculation with the value as base.
  • FormulaOperator.Set
    Sets the current variable value to the value.

Checking variables

All checking functions return a bool – true if the check is valid, false otherwise.

ORK.Game.Variables.Check(string key, string value)
Checks if the game variable (string) key is set to value.

ORK.Game.Variables.Check(string key, bool value)
Checks if the game variable (bool) key is set to value.

ORK.Game.Variables.Check(string key, float value)
Checks if the game variable (float) key is set to value.

ORK.Game.Variables.Check(string key, Vector3 value)
Checks if the game variable (Vector3) key is set to value.

ORK.Game.Variables.CheckFloat(string key, float value, ValueCheck type)
Checks the current value of the game variable (float) key against value using the check type.
ValueCheck is an enumerator and offers the following options:

  • ValueCheck.IsEqual
    The current value of the game variable (float)  is equal to the defined value.
  • ValueCheck.IsLess
    The current value is less than the defined value.
  • ValueCheck.IsGreater
    The current value is greater than the defined value.

ORK.Game.Variables.CheckVector3(string key, Vector3 value, float distance, ValueCheck type)
Checks the distance between the current value of the game variable (Vector3) key and the Vector3 value against distance using check type.
ValueCheck is an enumerator and offers the following options:

  • ValueCheck.IsEqual
    The distance is equal to the defined distance.
  • ValueCheck.IsLess
    The distance is less than the defined distance.
  • ValueCheck.IsGreater
    The distance is greater than the defined distance.