PDA

View Full Version : multiples of counter



frost_oni
December 1st, 2004, 12:59 PM
hello. i am trying to learn flash for my lectures, but i got stuck somewhere and was hoping that someone could help; how can make a counter that increments only for multiples of say, only 500 [ i.e 500, 1000, 1500, 2000, 2500.... ]. that's the cod ei use, but it's no good;



if (score == 500 || score == 1000 || score == 1500 || score == 2000 || score == 2500 || score == 3000 || score == 3500 || score == 4000) {
shield++;
maxAst++;
}


any help, please?

senocular
December 1st, 2004, 01:10 PM
look into the modulus operator

%

Dr Warm
December 1st, 2004, 08:08 PM
yes the good old % operator. It took me ages to figure out how to use it (even after reading flash help).

In case you've never used it it checks if the number you have is exactly divisible by another number, and then quotes the remainder.
eg. 24%4 = 0, 25%4 = 1 etc
so what you would do is:
if(score%500 == 0){


shield++;
maxAst++;
}
i think thats how it works!
</pre>

frost_oni
December 6th, 2004, 01:23 PM
sorry i haven't replied for so long. i have been drowned with uni courseworks, and it's been hell. ok, i tried the modulo, but it didn't work. so i put a trace in to see whether the function is being executed, and i found out that the if statement has been completely ignored and that the trace kept going on.

any help anyone?

Dr Warm
December 6th, 2004, 11:48 PM
You might have to post you're fla mate, it should work!

bbwd
December 10th, 2004, 01:52 PM
Hi, I think the code here is needlessly complicated:




if (score == 500 || score == 1000 || score == 1500 || score == 2000 || score == 2500 || score == 3000 || score == 3500 || score == 4000) {
shield++;
maxAst++;
}


Myself, I don't know about the & operator, but I think you can get around the problem with this code:






if (scorer == 500){

shield++;

maxAst++;

scorer = 0;

}




Then whenever you increase score, increase scorer by the exact same amount.