Friday 13 December 2013

Variables.. What are they?

Variables are an extremely important part of programming almost any game. A variable is basically a container that stores a value that you've set to it. Think of them as labeled jars, you can store data in them such as numbers or letters and to read this information again all you need to do is write the label on the jar. Variables can be changed by doing calculations to the variable name. Say, if you had a variable called 'Money' you can then set this to 200 by writing Money = 200. Then if you read the variable  'money' at anytime it will give you the value stored in the 'money' variable.
In actionscript there are 3 main variable types these include:

  • Numbers - Pretty obviously these store any number value.
  • Stings - These are used to store words/letters.
  • Boolean - These store only true or false.
Variables can come in more then these 3 varieties however most variables used will fall under these common types.

In most cases variables will only remember their set value till the game is ended, then any value stored will be lost. This is why in many games the values of every variable are saved to a file so that when you open the game again all the variables will load their values from the file.

No comments:

Post a Comment

Advertisement: