Flash ActionScript 2.0 Tutorial – Making a 1on1 Battle System – Beginners – Part 3

This is Part 3 of this tutorial. If you’re just now starting and need to go to Part 1, you can get there by clicking Part 1 in the Resources. Everyone else please read on.

Now go back to frame 2, press f9 to open the Actions window and type

stop();

if(_root.Hp gotoAndStop(“lose”);
}
if(_root.BadHp gotoAndStop(“win”);
}

You almost always want to have that stop function on your main frame. If not it’ll run right through this frame and go to the next ones and next thing you know you’ll have a never ending attack scene with all your characters going crazy and trying to annihilate each other. The second part

if(_root.Hp gotoAndStop(“lose”);
}

is saying that if and when your Hp is less than or equal to 0 it will go to the “lose” frame. You could also say gotoAndStop(5); because your “lose” frame is in the 5th frame but in the future when you have 100 frames, it’s sometimes easier to just name your frame something then say

gotoAndStop(“whatever_your_frame_name_is”);

than trying to figure out exactly which number it is. When you target a frame using it’s name rather than its number you have to use ” “. If not it won’t work. The third part

if(_root.BadHp gotoAndStop(“win”);
}

is the same as the second part only saying that if the enemies Hp becomes less than or equal to 0 it’ll go to the “win” frame.

Something to note – When I say less than or equal to I mean this

if(_root.BadHp–is less than or equal to–0){

If in the future you want something to do something when your number hits exactly a certain number you put == In your “IF” statements you always put == You only use one = in your statements that are between the { } brackets and when you’re setting up your variables. I believe there are other cases but I don’t feel like thinking about them right now haha.

Well that’s it for this tutorial. Press ctrl + enter to test your program and make sure it works. When you click attack both your characters should attack at the same time and their Hp should go down. If anything goes wrong or if you’re confused about any part of this tutorial please let me know. You can reach me at [email protected] (oh yeah…its real haha) Thanks for reading and good luck.


People also view

Leave a Reply

Your email address will not be published. Required fields are marked *