User Tools

Site Tools


developer_center:developer_editor:io_battle_gameplay

*How to use the Global Variable*

Back:
* Variable
* How to use the "Private Variable"
* *How to use the Global Variable*


10 minutes reading
Introduction
In the previous lessons, we learned about “the concept of Variable” and “how to use private variables”. In fact, the use of global variables are the same as that of private variables, but the application scenarios will be different.
If you have any unclear points in your study, you can click the link below to review the previous knowledge and deepen your understanding.
→ Variable (to understand variables by explaining the concept, function, naming rules, variable types)
→ How to use “private variables” (explain how to use private variables through real cases)

Guide
In this lesson, we will use a simple and interesting experiment to understand the application scenarios of global variables. At the same time, you will learn the following knowledge:
1. Create a global variable
2. Use global variables in triggers to control weather and creature behavior
3. Use plugins to create creatures
4. Make a simple UI and call it in the trigger

Game Scene
Global variables are more commonly used in the following two scenarios:
1. Used in games with strong online connection, the purpose is to allow all online players to share the data. For example, we use global variables to display scores and rankings.
2. Used to control the progress of the game world, such as NPC behavior, weather changes, etc.

Game scene: There is a Rain Timer to tell when it will rain. After it rains, NPC will gain a slowing effect and will cry when that happens. The global variables here play a role in controlling the game process.

[pic1]

So, let us follow the tutorial to realize the function!.

Create Global Variables Create two global variables to control the weather and NPC's behavior..
1. The “Creature type” global variable “NPC” is used to manage the behavior of NPC in the scene..
2. The “Timer type” global variable “Rain Timer” is used to manage the rain countdown time..

Trigger Logic.
1. Rain Timer Trigger Settings - When the game starts, start the Rain Timer..

[Tips: type #+ the first character of the color can change the words' color]

2. Initialize the NPC's trigger - create a creature as an NPC at a specific location when the game starts..

- Use a plugin to create a creature, named NPC, and turn off the creature's movement attribute

- Set Trigger logic: create NPC creatures, and assign NPC creatures to the global variable “NPC”

3. Weather Control Trigger settings - when the timer countdown reaches 0, the game starts to rain, NPC gets slowed down, and starts crying..

4. (Extra Knowledage) Set the notification UI for rainy days
- First, create a UI for Weather Reporting.

- Add logic to the trigger to display UI in the trigger for controlling the weather.

Exercise
Here is a practice. Welcome to challenge yourself:
Exercise: Use global variables to control the refresh of the world boss. When the world boss is coming in 5 seconds, notify all players.

It is worth thinking that although the use of global variables and private variables is similar, and sometimes the boundary of the usage scene is not very clear, we still need to standardize the use of global variables and private variables, which will help us lay a solid foundation for development Basic.

If you have mastered the application of global variables, you can click on the portal below and follow the tutorial to make a complete IO battle game:
Advanced Lesson: Play Variables in one game - *How to use the Global Variable*

developer_center/developer_editor/io_battle_gameplay.txt · Last modified: 2023/05/23 10:47 by fuheng