PDA

View Full Version : [AS2] Store creation in game (else and if question)


cdrake
09-15-2004, 01:39 AM
Ive got this code.


//Enough Sugar Pills?
onClipEvent (enterFrame) {
if ((_root.sugarpills>0)==false)
_root.buysugar.unloadMovie();
if ((_root.sugarpills>0)==false)
_root.pillstatus="Out of Stock";

//enough money?
else if ((_root.money>9)==false)
_root.buysugar.unloadMovie();
_root.pillstatus="Need more money!";

}


I want it to check to see if the item is out of stock then load the message. It works great until you put the Need more money. IT always insist on loading that even though you have more than 10 dollars.

madgett
09-15-2004, 01:54 AM
Take a look at the bold below, you are ending the else if () statement before the pillstatus string. You need to use curly brackets {} they help remove confusion.


//enough money?
else if ((_root.money>9)==false) {
_root.buysugar.unloadMovie();
_root.pillstatus="Need more money!";
}

Xeef
09-15-2004, 01:57 AM
hi

you using IF in a confusing way i thin that's whie its not working
a = 1;
if (!(a>9)) {
trace("1: "+a);
}
if ((a>9) == false) {
trace("2: "+a);
}
if ((a<9)) {
trace("3: "+a);
}
if (!(a>9) == true) {
trace("4: "+a);
}
(a<9) ? trace("5: "+a) : undefined;

cdrake
09-15-2004, 02:00 AM
Also,

I am trying to find a way to make it where when you buy a health pack, it wont let you have more than 100 hitpoints, but i dont really know an effective way to do this. Im trying to use this code, but whenever he walks in the store it automatically gives him 100 hp.


on(release){
_root.money-=25;
_root.healthpack-=1;
_root.hp+=25;
//Prevent from having over 100 HP.
if ((_root.hp>100)==true){
_root.hp=100;
}
}

madgett
09-15-2004, 02:15 AM
Take ==true out of your if() statement.

cdrake
09-15-2004, 02:25 AM
It still sets it to 100 automatically.

madgett
09-15-2004, 02:37 AM
Are you saying that when you push that button he's automatically getting 100 hp or when he just walks into the store?

cdrake
09-15-2004, 02:45 AM
when he just walks in the store.