
1. Re: how to check, how many times the modulo % start over.
Ned Murphy Jan 4, 2010 6:47 AM (in response to chrisatflash)I'm not sure what you are trying to do, so you may have to explain that more clearly. The value of my_value is constantly growing, well beyond 50, and the conditional... maxValue>=50 will never be satisfied. Due to the modulo operation there can never be a maxValue that is >= 50... the modulo returns the remainder after dividing by 50, which will always be < 50

2. Re: how to check, how many times the modulo % start over.
kglad Jan 4, 2010 6:47 AM (in response to chrisatflash)1 person found this helpfuluse:
Math.floor(my_value/50);

3. Re: how to check, how many times the modulo % start over.
chrisatflash Jan 5, 2010 12:50 AM (in response to kglad)Yes, i haven't been clear on what i am trying to do, but the only thing i am trying to accomplish is,
to run a function when the module starts over.
Thanks to the single line of Kglad i now got it working, but now every onEnterframe the loop function is called.
Is it also possible to run the updateLoop() function only when it changes, if there is a new value?This is the code i have so far:
var my_value = 0;
var my_speed = 4;
var countloops = 0;
this.onEnterFrame = function() {
my_value += my_speed;
doSomething(my_value);
}
function doSomething(myvalue) {
var maxValue = myvalue%50;
//to calculate how many loops there are going.
var checkvalue = Math.floor(my_value/50);
if(checkvalue == 1) {
updateLoop(checkvalue);
}
if(checkvalue == 2) {
updateLoop(checkvalue);
}
if(checkvalue == 3) {
updateLoop(checkvalue);
}
if(checkvalue == 4) {
updateLoop(checkvalue);
}
//and so on.
}
function updateLoop(loops) {
trace("this is loop number " + loops);
}

4. Re: how to check, how many times the modulo % start over.
Ned Murphy Jan 5, 2010 4:55 AM (in response to chrisatflash)What you'll want to do is have a currentValue that you compare against the checkValue. The currentValue starts at zero and only changes when the checkValue does not equal it. If they are equal then you don't call updateLoop function.... if they are not equal, that means the checkValue just changed again so you then want to call the updateLoop function and adjust the currentValue to once again equal the checkValue.

5. Re: how to check, how many times the modulo % start over.
chrisatflash Jan 7, 2010 12:41 AM (in response to Ned Murphy)Brilliant Ned! Thanks, i got it working now. This is the code and it's a lot smaller
var my_value = 0;
var my_speed = 4;
var countloops = 0;
this.onEnterFrame = function() {
my_value += my_speed;
doSomething(my_value);
}
var checkvalue = 0;
function doSomething(myvalue) {
if(checkvalue != Math.floor(my_value/50)) {
updateLoop(checkvalue);
}
//to calculate how many loops there are going.
checkvalue = Math.floor(my_value/50);
}
function updateLoop(loops) {
trace("this is loop number " + loops);
}