Variables, Trouble Understanding them

I tried watching Tutorials on Variables to try and get a grasp on understanding them better so I can use them for my game but I have a lot of trouble doing it so can someone explain to me how variables like Array, Structure, Number, and Text Variables work and how they can be implemented in things like Saving and Loading, Randomly Spawning Entities (Resources, Enemies, & NPCs), Missions and all that stuff.

Any Help would be greatly appreciated

You have nickname Taco2009 i have nickname ZeroX4
We both have nicknames
We call them nicknames
But in reality they are text/string variables

Variables = some value that may vary and from that we call them variables

EACH nickname you ever saw is text variable

What will happen if we add your nick to my nick?
We will get Taco2009ZeroX4
If we add my nickname to your nickanme we will get ZeroX4Taco2009

So adding text variables works like tetris blocks
Then join together in order in which you add them

So by now you should understand that variables are nothing else than containers of some informations

So folder name or file name is nothing else than text variable
Containing some text

Calculator is not using text on other hand
Calculator uses number variable
Difference is that with text adding AB to XX will result in ABXX
Where if you add text variable with 5 to text variable 3 you will get 53 cause you join them like tetris blocks and not make calculation
For that we have number variables

Number var 2 added to number var 4 will give us 6
Cause number variables allow us to make all kind of calculations on them
Add divide subtract multiply and whatever

Boolean variables are holding one of two values true or false
Or 0 or 1 (where 0 would be false and 1 would be true)

Idea is imagine it as light switch
You it don’t have lightness % like will it light bulb (well there are some light switches that do that)

BUT in this case we think about this

It have 2 states either On or Off nothing more nothing less
So again True or False state or 0 or 1
You can check if something is on or something of
If something is true or something is false

But why then use boolean if we could make number variable with either 0 or 1 value?

Because with number variables you have either set it to 1 or to 0

Boolean variables have action to toggle them
So imagine i tell you go and hit light switch
I did not specify do i want you to to turn it on or off
You did not ask should you turn it on or off
You was just ordered to go switch it (toggle it)

So in whatever state it is you simply toggle it to other state

So thx to this

I can toggle some variable by pressing same button
Toggile it to true if its false or toggle it to false if its true

And now in separate 2 events i check is it true or false
And based on that state i either play music or no

Just like light switch works

Structures and arrays are nothing else than folders for variables
Like imagine you want to give your player some stats
So you create structure variable called Stats
Now you add child to it and its just some number variable called HP with some number since its number variable
And then another variable called Exp

So now you have Stats.HP and Stats.Exp

Why you need structures and arrays? cause you can save them instead of saving individual variables one by one
And perform other things

Imagine
Option A you have 20 music files
You need to cut them from desktop and put into music folder ONE BY ONE

Option B put all of them inside Cool Songs folder and now you just cut and paste that Cool Songs folder to music folder

Where Structures have names for child variables just like each normal variable would have
And they are automatically sorted alphabetically

Where arrays do not have names for child vars but index number

Same as animations
You have your 1st animation as 0
2nd as 1
3rd as 2 and so go on
These numbers we call index numbers they are nothing else than this

image

Each position on this list have some number on the left
And that would be index number
Index number is just number of each variable in array
Same as each position on this list have its number on the left

And arrays child can be called by their index numbers

So you could have array called Weapon
Whcih would have two child variables
At index 0 so 1st child text var with text Shotgun
At index 1 so 2nd child text var with text Riffle

Now you would call them with Weapon[0] and that would display Shotgun
And Weapon[1] and that would display Riffle

Now what you also can do is make number variable like normal number variable and call it WeaponSwitch
And if you press 1 it switches to 0 and when you press 2 you set it to 1

And now with array variable you could do Weapon[WeaponSwitch]

And so prssing 1 would display Shotgun and pressing 2 would display Riffle

Cause instead of just giving static number of child which you want to select
You are using another variable value to dynamically switch whichever child is currently selected

That should give you most basic understanding to start trying to do something with vars
Testing what can you do with them will help you a lot

2 Likes