Related Knowledge

July 4, 2022

Related Knowledge

Variable

Variable can be used to store values. When defining a variable, you need to specify the name of the variable, the data type of the variable, and the value of the variable. A variable is like a container, you can modify and get its stored value.

Type

There are 3 types of variables in the Blockman Editor, and their scope is inconsistent:

Type Description
Global variable Global variables are shared by the entire game, and all game objects can access and modify global variables.
Entity variable Entity variables can only be accessed and modified by entity instances. For example, it can be used to record the score of a entity instance, the number of deaths, and so on.
Local variable The scope of the local variable is the current trigger graph.

Create variable

The steps to create a new global variable or entity variable are as follows:

1.Open the trigger editing window and click the “Variable” button in the toolbar.

2.In the variable management window, select whether you want to create a global variable or an entity variable, and then click the “New” button to open the variable new menu.

3.In the variable new menu, you can define the name, data type, default value, etc. of the variable. After the setting is completed, click the “Confirm” button to successfully create a variable.

It should be noted that: Currently, after creating a new variable, it is only allowed to delete the variable, and it is not allowed to modify the variable at the moment.

In the menu, you can define a series of variables. For each option, please refer to the following table:

Option Description
Variable name

The name of the variable. The variable name is used as the unique identifier of the variable. In the same scope, the variable name is not allowed to be repeated. In order to standardize the naming of variables, currently variable names can only consist of English letters, numbers and underscores, and they must start with a letter.

Type Set the type of the variable. For the detailed description of the data type, please refer to the Data Types.
Data Structure Set whether the variable stores data in the form of a single value or in the form of an array. In simple terms, an array can be regarded as an ordered collection of a series of values, one of which is called an element of the array, and you can access the elements in the data by index value. (The index value starts from 1, the element with the index value 1 represents the first element in the data, and so on).
Default value Set the default value of this variable.
Save Variable Value This option is only effective for the entity variable. When the player exits the game, the value of this variable will be automatically saved in the Blockman Go data backend. When the player enters the game again, the value of this variable will not be reset, but will continue to use the value of the previous data backend. For example, the player’s game points can be saved through this function, even if the player quits the game, the score will not be cleared.

For local variables, there is no need to declare them in the above-mentioned window. Local variables can be used directly in the trigger chart. When you set a non-existent local variable, the local variable will be automatically created and assigned a value.

For example, in the following figure, although we did not define the variable in advance, the node will automatically create a local variable named hp with a value of 100:

Set and get variable

You can use the “Set Variable” node to modify the value of a variable, and you can use the “Get Variable” node to get the value of a variable. Both of these nodes are located under the “variable” category, just create and connect the nodes directly.

Type

There are many types of data available in the editor, but in most cases, you will only use the following common types. The following only introduces the common data types:

Type Description
Integer A value without a decimal part, such as -2, 0, 100.
Decimal Values with a decimal part, such as 2.1, 6.5.
Boolean Boolean values have only two values, “true” and “false”, and are usually used for relationship judgment or state switching.
Entity entity instance.
Three-Dimensional Vector/Coordinate The form of the three-dimensional vector is (X, Y, Z), where X/Y/Z are all numbers, which are generally used to represent a point in the map.
Scene Coordinates It is similar to a three-dimensional vector, but in addition to a three-dimensional vector, the scene coordinates can also store a map instance.
String A combination of characters (can be understood as a piece of text) composed of numbers, letters, symbols, etc. For example, the player’s name, chat information, etc. are all strings.
Any Any type of value can be stored. Usually when you are not sure of the type of value you want to store, you can use this type of variable.