Skip to main content
Known Participant
March 29, 2013
Question

Buggy IF statement

  • March 29, 2013
  • 1 reply
  • 396 views

Here is the actionscript on the frame:

if (newscore>=_level0.score1){

trace("new high score");

trace("new score = " + newscore);

trace("old score = " + _level0.score1);

trace(newscore + ">=" + _level0.score1);

_level0.score1++;

newscore++;

trace("new score = " + newscore);

trace("old score = " + _level0.score1);

}else{

trace("not high score");

====================

Here is the output:

--------------------

new high score

new score = 5

old score = 10

5>=10

new score = 6

old score = 11

 


I am so confused on this output. The if statement compares two variables and says "if" the new score (newscore) is greater than or equal to the old score (_level0.score1) to do something. It is clearly not the case as you can see the new score is lower than the old score, but it is still acting like it meets the "if" requirement. This is for a local scoreboard using shared objects to store variables. I added the ++ to the variable to make sure the values were integers and not strings. What am I doing wrong here?

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
March 29, 2013

if you use:

if (newscore>=_level0.score1){

trace("new TRACE");

trace("new score = " + newscore);

trace("old score = " + _level0.score1);

trace(newscore + ">=" + _level0.score1);

_level0.score1++;

newscore++;

trace("new score = " + newscore);

trace("old score = " + _level0.score1);

}else{

trace("not high score");

}

and you're trace output is:

new TRACE

new score = 5

old score = 10

5>=10

new score = 6

old score = 11

post a link to your zipped source files. 

if you're trace is the same as the one you posted, you have other code causing that problem.