PDA

View Full Version : Negating Code?!?



Holmesc
January 23rd, 2007, 11:51 PM
'm currently making a game involving a timer and energy. Intriguing already, no? Anyway, I have two separate pieces of code controlling each element. However, when I run them at the same time, only the code for the timer works. I don't know why this happens... I know that it isn't the variables for each part, but something in the code. Yes, I've tested this extensively. Here's some code, located in the _root timeline (I would put it in actionscript tags, but stuff is being spazz):



var energy:Number = 100;
var generator_percent:String = Math.round(energy)+"%";
var minutes:Number = 0;
var seconds:Number = 0;
var timer:String = minutes+":"+seconds;
//Energy code and generator_percent variable updating
onEnterFrame = function () {
generator_percent = Math.round(energy)+"%";
if (energy>0) {
energy -= 0.2;
}
};
//Timer code
onEnterFrame = function () {
seconds += 1/24;
if (seconds>59) {
seconds = 0;
minutes += 1;
}
if (seconds<=9) {
timer = minutes+":"+"0"+Math.round(seconds);
}
if (seconds>=10) {
timer = minutes+":"+Math.round(seconds);
}
};

In case it makes a difference in some way, the movie is running at 24 fps.
I can't see any way that the timer script would stop the energy script from working, can you? If you think it would help, tell me to post all of the code for the game (I'm just showing the code I think is important). Thanks for your help.

SacrificialLamb
January 23rd, 2007, 11:59 PM
You are probably going to kick your self but i am pretty positive that the code is not working because you can not have 2 onEnterFrame's in the same _root

TheCanadian
January 24th, 2007, 12:18 AM
That's right, each movie clip can only have one value associated with each property.

Holmesc
January 24th, 2007, 09:15 PM
Really? I've done that before I think, although I'm not sure. I'll change it, though... LATERNESS: And, it works. Maybe I haven't had double onEnterFrame-s. Frames. Frame-s. Anyway, it works now, and I would kick myself, but it's sort of an uncomfortable position. Thanks guys!