# Global Variables

Entrance：Top Asset Library>>>Global variables

<figure><img src="/files/aycDaCcDaIA3NqjQCJgJ" alt=""><figcaption></figcaption></figure>

## 📒<mark style="color:blue;">What is Global variables？</mark>

* 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).&#x20;
* 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 <mark style="color:red;">simplify the production process</mark> by enabling us to handle complexity more effectively.

####

## 📒<mark style="color:blue;">Global variables usage instructions</mark>

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. Adding “Variables”

1）Add variables：click“Global variables” - “+Add variables”

2）Configure the newly added variables

* Name: Enter the variable name (customizable).&#x20;
* 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).&#x20;
* Description: Enter a description for the variable (optional).

<figure><img src="/files/VwObdtAerO5olvGfGXac" alt=""><figcaption></figcaption></figure>

**Attachment：Variable Type Table**

<table data-full-width="false"><thead><tr><th width="167">illustration</th><th width="123">Variable Type</th><th width="136">supplement</th><th>Operating instructions</th></tr></thead><tbody><tr><td><img src="/files/yN9Ed3BxPVGxeb2XC5Vg" alt=""></td><td><strong>Number</strong></td><td>Can input any number as initial value</td><td><p></p><ul><li>Commonly used for calculations, including size comparisons and addition, subtraction, and multiplication.</li><li>When the variable equals different values, different behaviors can be triggered.</li><li><mark style="color:red;">For example, clicking an element, the parameter variable accumulates according to the click times, and accumulating different values can trigger different behaviors.</mark></li></ul></td></tr><tr><td><img src="/files/XTNbyTLm2KrfSYUrXdk5" alt=""></td><td><strong>String</strong></td><td>Can input any text as initial value</td><td><p></p><ul><li>Used to pass the value of text attributes. User-entered text can be assigned to parameters and executed with conditions.</li></ul></td></tr><tr><td><img src="/files/bBemuqOdbGMmH2zw9xtZ" alt=""></td><td><strong>Boolean</strong></td><td>Can choose between "True" or "False" as initial value</td><td><p></p><ul><li>Used to pass boolean values. User-selected boolean values can be assigned to parameters and executed with conditions.</li></ul></td></tr></tbody></table>

### 2.**Add "Conditon"**

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.&#x20;

<table data-full-width="false"><thead><tr><th width="198.33333333333331">Type</th><th width="407">Operating instructions</th><th>illustration</th></tr></thead><tbody><tr><td>Directly add "Condition" event</td><td><ul><li>Click to add an event</li><li>Select criteria judgment</li><li>Add conditions: select global variables, judgment method, comparison variable type, comparison value</li><li>After selecting, check √ to successfully add the 'Condition Judgment' event</li></ul></td><td><img src="/files/n5adCKqnDkWnngKjWiSQ" alt=""></td></tr><tr><td>Add "Conditon" Event Above Other Trigger Events</td><td><p></p><ul><li>Click on the 'Condition Judgment' next to the triggering event</li><li>Add conditions: select global variables, judgment method, comparison variable type, comparison value</li><li>After selecting, check √ to add a 'Condition Judgment' event above other triggering events</li></ul></td><td><p><img src="/files/WXYAlBwHCGniKiyFSMgk" alt=""></p><p></p><p> <img src="/files/Q3cKAcKYl6pT5U3CFmoS" alt=""></p></td></tr></tbody></table>

**Attachment: Parameter Table for Condition**

<table data-full-width="false"><thead><tr><th width="211.66666666666669">illustration</th><th width="214">Parameter</th><th>Operating instructions</th></tr></thead><tbody><tr><td><img src="/files/Qlztg7JbXCir431PMUN6" alt=""></td><td>Global variables</td><td>Select an existing global variable for Condition</td></tr><tr><td><img src="/files/IIxKGQ8Rm6qpxXaHS4Ej" alt="">   <img src="/files/xhTC23vXsp4xribhMC9O" alt=""></td><td>Judgment Method</td><td><p>When the global variable is number, it can be compared by size or equality(left)；</p><p></p><p>When the global variable is string or boolean, it can only be compared for equality,equal to or not equal to(right).</p></td></tr><tr><td><img src="/files/dnJgAynEuu61WpxtKBCk" alt=""></td><td>Comparison Variable Type</td><td>Select the "current global variable parameter type" or other "global variables" to compare.</td></tr><tr><td><img src="/files/9bVkGYkeTTjN71u7rKnN" alt=""></td><td>Comparison Value</td><td><p>Enter the same type of value to be compared based on the current global variable parameter type.</p><p>For example, if the current Condition is a Boolean variable, the comparison value can only be a Boolean value.</p></td></tr></tbody></table>

### **3.Add "Response Events"**

**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."

<table data-full-width="false"><thead><tr><th width="232.66666666666669">Type</th><th width="389">Operating instructions</th><th>illustration</th></tr></thead><tbody><tr><td>Assign the value</td><td><ul><li>Add Response Event</li><li>Select [Assign the value]</li><li>Select global variables, operation methods, and operands, and click Save to save them.</li></ul></td><td><p><img src="/files/GA6rwlPU8PqXbCW5uSbM" alt=""></p><p></p><p><img src="/files/WgAf6XdzIKfZKgY0gAgD" alt=""></p></td></tr><tr><td>Other Response event</td><td><p></p><ul><li>Directly add a response event under Condition Judgment</li><li>Simply select the response event</li></ul></td><td><img src="/files/jJLXeyBKAp12B6VlJoOD" alt=""></td></tr></tbody></table>

**Attachment: Response Event - Assignment Parameter Table**

<table data-full-width="false"><thead><tr><th width="220">illustration</th><th width="180.33333333333331">Parameter</th><th>Operating instructions</th></tr></thead><tbody><tr><td><img src="/files/Ail9DCOEa3pbVhutcUzD" alt=""></td><td>Global variables</td><td><ul><li>Select existing global variables for assignment.</li></ul></td></tr><tr><td><p><img src="/files/d9tUrrKnSWU6Z4papuQl" alt=""></p><p></p><p><img src="/files/2ZZGSgxsIEjS7pjwdbmu" alt=""></p></td><td>Operation method</td><td><ul><li>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);</li><li>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);</li></ul></td></tr><tr><td><img src="/files/4A4PmkZitMyvxM3DJwQC" alt=""></td><td>Operand</td><td><ul><li>You can select the parameter type of the current global variable or other global variables for operation;</li></ul></td></tr><tr><td><img src="/files/TkI6qggcT6o1r3BQVv3h" alt=""></td><td>Operand value</td><td><ul><li>Enter the same type of numerical value that needs to be calculated based on the current global variable parameter type. </li><li>For example, if the current condition is judged as a Boolean variable, the comparison value can only be a Boolean value;</li></ul></td></tr></tbody></table>

### 4.Supplement：Add Multiple "Condition"

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.

<table data-full-width="false"><thead><tr><th width="135.33333333333331">Type</th><th width="487">Operating instructions</th><th>illustration</th></tr></thead><tbody><tr><td>And</td><td><ul><li>Add other conditions to the existing condition</li><li>+Add conditions, select global variables, judgment methods, comparison variable types, and comparison values</li><li>Check Save to save</li></ul></td><td><img src="/files/lX44FnF5k27bKhCA6kPc" alt=""><img src="/files/15BzGyXIDly3Iz20i0jP" alt=""><img src="/files/GWLwJRaSJJH0uBPejMsj" alt=""></td></tr><tr><td>Or</td><td><ul><li>Add a “condition”</li><li>+Add conditions, select global variables, judgment methods, comparison variable types, and comparison values</li><li>Check Save to save</li></ul></td><td><img src="/files/03cOrrBAuqm8fKos9G2E" alt=""><img src="/files/bpIdtM0ZzcN1Cy2qVm11" alt=""><img src="/files/6YA8XPJ4ZJmtufFU4EeP" alt=""></td></tr></tbody></table>

####

## 📒<mark style="color:blue;">Examples of Application Scenarios</mark>

Having understood global variables and their operational steps, let's delve deeper into the topic by exploring two more examples.

### 1.Restricting Trial Interactions

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.&#x20;
* Global Variable: A simple and quick implementation in three steps.

<figure><img src="/files/Lfod0nHSQSo3wxGXTp0C" alt=""><figcaption></figcaption></figure>

### 2.Different Results Based on Multiple Choices

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.

<figure><img src="/files/ceEagk6MxJC6PL59touI" alt=""><figcaption></figcaption></figure>

Through the above two examples, it becomes evident that <mark style="color:red;">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.</mark>

Related content： [Creation Tips - Event Setting](/playable-tools-content-editor/content-editor-creation-tips-center/common-creation-tips/creation-tips-event-setting.md)

####

## 📒<mark style="color:blue;">Global Variables-Teaching Video</mark>

👉Click to view detailed case explanations: [Dress-up - Blank Canvas Tutorial](/playturbo-case-study/playable-content-editor/decoration-gameplay-cases/dress-up-blank-canvas-tutorial.md)

{% embed url="<https://mmp-cdn.rayjump.com/res_store/1863769/646dda30dfd72.mp4>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.playturbo.com/playable-tools-content-editor/content-editor-user-guide/editing-page-module-intro/top-asset-library/global-variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
