There are many ways, and reasons, to use variables. In a game: if you want to be able to buy something, keep stats, keep count of something, or make a true or false clause. In a video, or music player: you might want to keep a play count or something that adds up. Those are some of the reasons you might want to use variables.
First we will start our with in games...
Buy Something:(COPY AND PAST THE WHOLE SCRIPT)
- //script written by stat for buying something, a watch
- //view more scripts for free at www.max-flashtutorials.blogspot.com
- on (release){ //on release of the button
- if (watch == false) { //if you dont already have the watch
- if (money>49) { //if the equals money is 50 or higher
- _root.money-=50; //you spend fifty dollars
- _root.watch = true; //you now have the watch
- _root.watchbutton._alpha = 0; //the button to buy the watch is now invisible
- } //ends money if
- } //ends watch is false if
- } //ends on realse part
- //script by stat
Copy and paste that script on the button. You will have to change the names of the variables to comply with the ones your working with, and the "watchbutton" should be the istance name of the button to buy what ever you are dealing with. Leave anything after the "//" it will affect nothing but will be helpful to look back on latter if you forget what something does or want to write your own script.
Keep Stats:
(COPY AND PAST THE WHOLE SCRIPT)
- //script written by stat for buying something, a watch
- //view more scripts for free at www.max-flashtutorials.blogspot.com
- on (release) { // on the release of the button
- if (money>19) { // if your money equals 20 or higher
- _root.intelligence +=1; //intelligence is uped by one
- } //ends money if
- } //ends on release part
- //script by stat
Copy and paste that script on the button. You will have to change the names of the variables to comply with the ones your working with. Leave anything after the "//" it will affect nothing but will be helpful to look back on latter if you forget what something does or want to write your own script.
Everything else is pretty much the same thing, you just use different variable names...
Please comment if you have any questions!