New to ActionScript 3.0 - Got some questions with IF statements!
Let's say I'm creating a game where you can edit character skills.
For now, there is only the "endurance" valuable, which is 10. You can decrease it, but I want it to stop at 5 (as a hero with 0 or negative endurance would be meaningless).
I have two questions, but let's look at the code first:
//Defaults var hero_endurance:int = 10;
var string_hero_endurance:String = String(hero_endurance);
box_hero_endurance.text = string_hero_endurance;
//Endurance Controls function hero_endurance_decrease(MouseEvent😞void{
hero_endurance = hero_endurance-1;
var string_hero_endurance:String = String(hero_endurance);
box_hero_endurance.text = string_hero_endurance;
}
if (hero_endurance > 5){
button_hero_endurance_down.addEventListener(MouseEvent.CLICK, hero_endurance_decrease);
}
Now my first question:
This code doesn't work. The valuable keeps going down (below 5), like the if statement isn't there at all. How can I fix this?
Second question:
Maybe you have noticed, the function always refreshes the valuable in the text box by:
var string_hero_endurance:String = String(hero_endurance);
box_hero_endurance.text = string_hero_endurance;
Actionscript 2.0 didn't even require such a code, any change you did to a valuable would reflect in a text box. Is there a simple way to do this, or do I have to use this code for each and every case?
Thanks on advance!
