Loop the loop; advice sought
Posted: Fri Jul 18, 2008 1:37 pm
I need to move 10 actor clones named `Cube` across the screen, individually,moving slowly across 40 pixels, not in 40 pixel jumps.
Only the selected Cube is to move. Note that my code works, I've left out other code and variable declares to
keep it compact so syntax etc isn't the problem here.. I just need some extra code to repeat the code correctly.
Explanation:
The array CubeMove[10] holds a `1` for the corresponding cube actor that is to move.
If 1 is found, a check is then
made to ensure the Cube clone is not already moving (xvelocity==0)
The Cube actors name is then formatted with the correct clone index number (i.e Cube.1) with
sprintf and the correct clone then is moved with MoveTo. Fine. My problem is that if the above code is
triggered, it works just once. I've tried to put the above into an outer, nested loop to make it
carry out the MoveTo command say 5 times in 1 loop but it won't. Or if it does the screen doesn't update
the movement with the outer loop. The only way is to trigger it, say with a keypress, by pressing the key
5 times. I want to repeat it say 5 times, with a variable value like e.g Numberofmoves=5 automatically.
Hope this is clear enough.
example code:
for(i=0;i<10;i++) {
if ((CubeMove[i] ==1) && ( getclone2("Cube",i)->xvelocity==0))
{sprintf(cubemove, "Cube.%ld",i); MoveTo(cubemove, 40.0, 0, 2.0, cubemove, "");
}
Only the selected Cube is to move. Note that my code works, I've left out other code and variable declares to
keep it compact so syntax etc isn't the problem here.. I just need some extra code to repeat the code correctly.
Explanation:
The array CubeMove[10] holds a `1` for the corresponding cube actor that is to move.
If 1 is found, a check is then
made to ensure the Cube clone is not already moving (xvelocity==0)
The Cube actors name is then formatted with the correct clone index number (i.e Cube.1) with
sprintf and the correct clone then is moved with MoveTo. Fine. My problem is that if the above code is
triggered, it works just once. I've tried to put the above into an outer, nested loop to make it
carry out the MoveTo command say 5 times in 1 loop but it won't. Or if it does the screen doesn't update
the movement with the outer loop. The only way is to trigger it, say with a keypress, by pressing the key
5 times. I want to repeat it say 5 times, with a variable value like e.g Numberofmoves=5 automatically.
Hope this is clear enough.
example code:
for(i=0;i<10;i++) {
if ((CubeMove[i] ==1) && ( getclone2("Cube",i)->xvelocity==0))
{sprintf(cubemove, "Cube.%ld",i); MoveTo(cubemove, 40.0, 0, 2.0, cubemove, "");
}