Introduction Edit

CoreBrainTileCommand CreateNumberVariable Number Variables have the ability to store numerical values during gameplay and work just as similar as placing a number. However, the main advantage of using a number variable is the ability to change the value when a certain pre-defined action is performed, thus having dynamic values for selected operations. Using number variables, one can track values in certain properties (ones that contain numbers, like jump height, damage, health etc.), or modify those values accordingly.

WHEN and DO Edit

The main difference between the two sections is that DO can only store a number inside a variable or assign the variable into a property (like global water level), while WHEN asks whether a statement is true, based on comparing or tracking any change in the variable.

Storing a number (DO) Edit

To store a number we process the equation like most of programming languages. That means that the entity that will store the value will go left and the value to be stored to the right:

Number Variable example 2

This will store the number "1" in the "Example Number Variable" we created, and unless we store something different, it will never change for the duration of the game session.

Assigning a number (DO) Edit

To assign a number into a property, we again follow the previous step but now the variable goes to the right (value to be stored) and the property we want to the left of the equation (value to be changed). So below we change the speed of the actor that holds the brain using the stored number inside our "Example Number Variable":

Number Variable example 3

This will make the walking speed of the brain's owner "1".

Comparing a number (WHEN) Edit

However, if we want to ask the brain if a certain value is contained in the variable, we use the WHEN section instead.

So in WHEN we have:

Number Variable example 1

This will only enter the DO section if "1" is equal to the number stored inside the variable.

Different comparisons also allow for more complex tests before entering the DO section. Below is a list of more comparisons:

CoreBrainTileOpGreaterThan CoreBrainTileOpLessThan CoreBrainTileOpGreaterThanOrEqualTo CoreBrainTileOpLessThanOrEqualTo CoreBrainTileOpNotEqualTo

Tracking change (WHEN) Edit

Besides these comparisons, the brain editor can also track for any change in the number variable. These tiles however, are more generic and do not accept a value after placed on WHEN like the previous comparisons. They also allow the brain to enter the section only once per change of the stated value. Those tiles are the following:

CoreBrainTileOpDecreased CoreBrainTileOpIncreased CoreBrainTileOpChanged

So in this example, the following shows that we initially set our number variable to hold the number "2". This will skip the second line because the value is not changed yet, then the third line will change the variable's number to "1". After the page is run again, the brain will now enter the second line as the previous value when the brain run this line is different than the new value. After that, it will never enter it again as the value will keep on being "1".

Advanced Edit

Below will cover a few more avanced topics you may encouter while working with numbers.

Limits Edit

A number variable default is 0 if not stated and can store numbers between the range of -10,000,000,000 and 10,000,000,000. Also, numbers below 0.0001 will be displayed as 0, even if they are not stored as 0 in the memory (note that you can display more digits by multiplying the number by a power of ten). More information about the limits are available in Editor/Kode Limits.

Initiating a Number Variable Edit

The editor only sets the number 0 as a default value if the user does not assign a number to that variable before asking to present the value inside a statement. To illustrate a common misunderstanding, we will compare the previous example with a similar one that doesn't initiate the value first.

Number Variable example 4

Even though this example looks different than the previous one, it does exactly the same thing, which is to run the page once and then jump on the second iteration. However, one may wonder why jump is activated the second time if the number is only stated once as "1"? The reason is the default initiation of the variable to "0" by the brain, because the variable was asked before being stated by the player as "1". So the change from "0" to "1"  below makes the first line work for one time in the second run.

Number Variable example 5