I was camping 3 months before i decided to get into variables
Because i was sure it some high level technical stuff
Never in my life i was so wrong
Imagine variables as indicators of something
Which you can turn to something or check if they are something
Most simple example
There are boolean variables
As cryptic as that sounds they have only 2 states False (set by default so if you create boolean variable it default state will be False) and True
So in other words you can say they are either 0 or 1
OR turned OFF or turned ON
So most basic example we have light bulb
Now imagine you place that bulb in your game and by default it is in False state (off)
Now you have ability to
- check state of that variable (is it true or is it false)
- toggle its state (if it is in true state this action will toggle it to false state and if it is in false state this action will toggle it to true state)
- set it state to false or true (no matter at what state it is you can set it to one of these 2 states at will)
Now imagine it as that bulb
You check if it is turned ON or turned OFF
You can with one button always turn it OFF or with another button turn it ON
You can toggle it state so if it is turned ON it will turn it OFF and vice-versa
Imagine you have condition cursor is on start button
And you make action for that condition to set boolean variable named LightBulbState to True
And another event
Where in condition you have that if mouse cursor is NOT on start button
Set Light BulbState to False
Now you can check at any point in your game with any event
In condition
If LightBulbState = Trune (bulb is turned ON or as you wish cursor is on start button)
And it is as simple as that
Now there are number variables that works more or less the same
But instead of True and False state they have well numbers
So you can do a counter
For each pepperoni you add to your pizza you change Ingredients number variable Add +1
And so number of that variable went from 0 to 1
You added another one and now variable from 1 to 2
Maybe you wanna do something different?
Like HP of your player
You make event
Condition
At beginning of the scene
Action
Change object number variable Player.Variable(HP) set to 100
This instead of adding a number will simply change this variable number to 100
Now you can do event like
Condition
Plyer is in collision with bullet
Action
Change object number variable Player.Variable(HP) subtract 5
So each time player is in collision with bullet this event will subtract 5 from Player HP variable 5
Now you can use text object to display this HP variable as text
For example you create text object place it on your scene and in event
Condition
NONE
Action
Modify text of NewText (<- this will be name of new text object) set to
ToString(Player.Variable(HP))
And now it will display player current HP
As for if one of these conditions is true
There are few of these types of conditions
Click add condition
And in search bar type
I think there are few more but i never used them and these are the ones you will actually use
If you need/want to learn more about variables i can explain more give more examples and teach you
BUT trust me you are just like me believing they are more complicated and cryptic than they actually are
For another example
In this order from top to bottom
Global
Scene
Object
variables are called in events with
- GlobalVariable(VARAIBLENAME)
- Variable(VARIABLENAME)
- OBJECTNAME.Variable(VARIABLENAME)
For example you do not want to go with object variable for player
But global variable
Then instead of Player.Variable(HP)
You would go with GlobalVariable(PlayerHP)
I changed name from HP to PlayerHP
Because if you for example have boss you can’t have 2 global variables with same name which would be HP
So instead you would go with
GlobalVariable(PlayerHP)
GlobalVariable(BossHP)
And you can set them to whatever you want and change them when each object is in collision with something or at some position