Global Variables
#Content Editor
Last updated
#Content Editor
Last updated
EntranceοΌTop Asset Library>>>Global variables
Global Variables are a special type of event parameter that can be accessed across all scenes, allowing for cross-scene usage (unlike regular events, which are limited to the current scene).
By adding global variables, you can trigger the desired response events in different scenes by evaluating the current value of the global variables.
The value of global variables can be number, string, or boolean (true or false).
Global variables are particularly useful when working with complex gameplay elements where a large number of events need to be set up or when regular events alone cannot achieve the desired functionality. They help simplify the production process by enabling us to handle complexity more effectively.
In essence, we usually need three steps to achieve the output of a global variable:
Adding variables
Place the global variable in the appropriate location and set the variable type according to the actual requirements (number, string, or boolean).
Adding condition
Add condition to implement "triggering the corresponding response event only when the condition is met."
Adding response events
Next, we will proceed with a detailed explanation step by step.
1οΌAdd variablesοΌclickβGlobal variablesβ - β+Add variablesβ
2οΌConfigure the newly added variables
Name: Enter the variable name (customizable).
Variable Type: Select the data type, including number, string, or boolean.
Initial value: Enter the initial value based on the selected variable data type (the initial value can be any value).
Description: Enter a description for the variable (optional).
AttachmentοΌVariable Type Table
Number
Can input any number as initial value
Commonly used for calculations, including size comparisons and addition, subtraction, and multiplication.
When the variable equals different values, different behaviors can be triggered.
For example, clicking an element, the parameter variable accumulates according to the click times, and accumulating different values can trigger different behaviors.
String
Can input any text as initial value
Used to pass the value of text attributes. User-entered text can be assigned to parameters and executed with conditions.
Boolean
Can choose between "True" or "False" as initial value
Used to pass boolean values. User-selected boolean values can be assigned to parameters and executed with conditions.
1οΌConditon adds a constraint to the event. The event is triggered when this condition is met; otherwise, the event is not triggered.
2οΌConditon can be directly added as a trigger event, or it can be added above any other trigger event.
Directly add "Conditon" event: Response events are triggered in real-time in the scene. When the Conditon is true, the response event will be triggered immediately.
Add "Conditon" event above other trigger events: Response events are triggered only when a triggering event (such as clicking) occurs in the scene.
Directly add "Condition" event
Click to add an event
Select criteria judgment
Add conditions: select global variables, judgment method, comparison variable type, comparison value
After selecting, check β to successfully add the 'Condition Judgment' event
Add "Conditon" Event Above Other Trigger Events
Click on the 'Condition Judgment' next to the triggering event
Add conditions: select global variables, judgment method, comparison variable type, comparison value
After selecting, check β to add a 'Condition Judgment' event above other triggering events
Attachment: Parameter Table for Condition
Global variables
Select an existing global variable for Condition
Judgment Method
When the global variable is number, it can be compared by size or equality(left)οΌ
When the global variable is string or boolean, it can only be compared for equality,equal to or not equal to(right).
Comparison Variable Type
Select the "current global variable parameter type" or other "global variables" to compare.
Comparison Value
Enter the same type of value to be compared based on the current global variable parameter type.
For example, if the current Condition is a Boolean variable, the comparison value can only be a Boolean value.
Response events can perform "Assign the value" of added variables or trigger "response event."
"Assign the value": Assign values to variables, change variable values, and trigger different Condition.
"Response event": Trigger other response events such as "click" and "jump to the next scene."
Assign the value
Add Response Event
Select [Assign the value]
Select global variables, operation methods, and operands, and click Save to save them.
Other Response event
Directly add a response event under Condition Judgment
Simply select the response event
Attachment: Response Event - Assignment Parameter Table
Global variables
Select existing global variables for assignment.
Operation method
When the global variable is a number value, free addition, subtraction, multiplication, and division operations can be performed on the variable (as shown in the figure above);
When the global variable is a String or Boolean value, only equality judgment can be performed on the variable (as shown in the figure below);
Operand
You can select the parameter type of the current global variable or other global variables for operation;
Operand value
Enter the same type of numerical value that needs to be calculated based on the current global variable parameter type.
For example, if the current condition is judged as a Boolean variable, the comparison value can only be a Boolean value;
When multiple Conditions need to be added in a scene simultaneously, there are "and" and "or" relationships:
"And": Trigger response events when all conditions are met.
"Or": Trigger response events when any one condition is met.
And
Add other conditions to the existing condition
+Add conditions, select global variables, judgment methods, comparison variable types, and comparison values
Check Save to save
Or
Add a βconditionβ
+Add conditions, select global variables, judgment methods, comparison variable types, and comparison values
Check Save to save
Having understood global variables and their operational steps, let's delve deeper into the topic by exploring two more examples.
When we want to limit the number of interactions during a trial period, such as requiring users to click on a video 3 times before redirecting them to the store:
Regular Event: Setting this up can be complex.
Global Variable: A simple and quick implementation in three steps.
When creating content for gameplay scenarios such as a "Choose One out of Three" situation, where each button option leads to different outcomes:
Regular Events: This approach would require the use of four scenes and significantly increase the number of events.
Global Variables: By utilizing global variables, you can reduce the number of scenes to two and greatly decrease the total number of events required.
Through the above two examples, it becomes evident that using global variables can significantly reduce the number of scenes and the amount of response events required. This approach helps avoid repetitive production steps and enhances overall efficiency in content creation.
Related contentοΌ Creation Tips - Event Setting
πClick to view detailed case explanations: Dress-up - Blank Canvas Tutorial