How to understand the use of variables

Don't know how to make something and can't find a tutorial? Ask for one here.

How to understand the use of variables

Postby mog440 » Tue Dec 16, 2014 1:10 pm

Hi,
One of the hardest things I have found (so far) in GE is trying to understand the use of variables.
It is one thing being able to declare a variable, but when and how to use them seems a whole different story.
Just wondering if there is a good tutorial on the use of variables, or if some kind person could make one. Something explaining what to do and the reasons for doing it.
I am just starting to understand variables and it is getting a little complicated, with the if's, else if's, case 0's, breaks, ==1's etc,
There has got to be an easier way to grasp it all than downloading demo's and reverse engineering them to suit?
Thanks, Mog.
mog440
 
Posts: 12
Joined: Mon May 24, 2010 11:02 am
Score: 0 Give a positive score

Re: How to understand the use of variables

Postby Hares » Tue Dec 16, 2014 10:03 pm

For me variables are like boxes. You use them to store stuff in.

When you create a variable, it is empty - so it is like an empty box.
Then you can assing a value to it - you fill the box.
Then you can read the value at some other time, or from some other code - you look what is in the box.
Or you can change the value - you take out what is in the box, and put there something else.

In game-editor there are two kinds of variables:
Global:
These variables only exist one time in the game. An example is the score (in a one player game)

Actor:
These variables exist for each actor in the game. An example is the x or y position.

Game editor comes with a number of predefined variables:
http://game-editor.com/Variables

But you can create as many other variables as you like (or need).

How to create them, and what kind of variable can you make?
See this link http://game-editor.com/Creating_variables

So the only variable that doesn't really fit the box description is the array.
An array is more like a closet full of boxes.
So you can have an array with a size of 10, that means you have 10 boxes in the closet.
Then you can fill each box with a value, and do all the stuff you can do with "normal" variables.
Just keep in mind that the first box in the closet is number 0. So the tenth box is number 9.

I hope this makes sense :D
User avatar
Hares
 
Posts: 105
Joined: Fri Dec 20, 2013 8:39 pm
Location: Belgium
Score: 14 Give a positive score

Re: How to understand the use of variables

Postby gamemakerdude » Wed Dec 17, 2014 1:53 am

Couldn't have said it better myself, but I would like to add, I tend to think of a variable's name as label on the box also, because when I box up a bunch of stuff that I will later have to go thru to find certain things I generally label it so that when I am looking for something later, I know where to look for it. Such as a box named "Bathroom Stuff" or whatever. My particular point being, you want to name variables according to the data they pertain to so that when you want to manipulate it, the names come to mind easily. This may seem like common sense, but you may have many variables with similar names in a large project so it is important to know what data they keep track of.
User avatar
gamemakerdude
 
Posts: 72
Joined: Thu Sep 13, 2012 4:12 pm
Location: Texas
Score: 7 Give a positive score

Re: How to understand the use of variables

Postby mog440 » Wed Dec 17, 2014 12:35 pm

Awesome! Thanks so much for the replies, I am beginning to understand. Might take me a while tho :roll:
A very Merry xmas and new year etc, thanks for your help :)
mog440
 
Posts: 12
Joined: Mon May 24, 2010 11:02 am
Score: 0 Give a positive score


Return to Tutorial Requests

Who is online

Users browsing this forum: No registered users and 1 guest