Page 1 of 1

Efficient DELAY command needed

PostPosted: Fri Jul 06, 2007 6:15 am
by akhad
If I have a row of cloned objects called Tile, and I display them in a row on screen, I wish to update their animation frames but it all happens too quickly. I want to see each tile update for a split second rather than whizz straight through them, like a WAIT command works in other languages e.g

int a;
for (a=7;a< 11;a+=1)
{ getclone2("Tile",a)->animpos +=1; WAIT 5; }

How can I add an efficient delay to a For/Next loop where the imaginary WAIT command is?

PostPosted: Fri Jul 06, 2007 8:02 am
by Fuzzy
So you need a sleep, eh?

First, put the delay before creating the tile. Next, write a small function.. basically, its just a loop that does nothing.
Code: Select all
void Wait(int pause)
{
    int Sleeptime;
    int Dummy;
    for (Sleeptime = 0; Sleeptime < pause; Sleeptime++)
    {
        Dummy++; // This may not take enough time. Use some action that just kills time for no effect.
    }
} // end of Wait function


Now this is just rough. Its not tied to milliseconds or anything, but it should work for your purposes.

use it like this:

Code: Select all
int a;
for (a=7;a< 11;a+=1)
{ Wait(4294967295); getclone2("Tile",a)->animpos +=1; }


You will need a biiig number in there. Or repeat it several times. start large and work your way down till you get a pleasing delay.

I'll do a millisecond version soon.

PostPosted: Fri Jul 06, 2007 8:54 am
by akhad
Thanks Fuzzy. Have a point !

I was curious as to why GE doesnt have a built in WAIT command.

*Edit* Ok, got it running through Global Codeas a function.
Thanks again.

PostPosted: Fri Jul 06, 2007 9:24 am
by Kodo
If you wanted to avoid writing too much code you could do it just as easilly with timers (which are built in to GE).

PostPosted: Fri Jul 06, 2007 11:23 am
by DocRabbit
*UPDATED* NEVERMIND, just realized timer here won't work on individual clone.Time for work, Will try to come up with a working solution tonight.

The timer event could be something like this. In the event that you want to start the first tile animation to change, do this.

Code: Select all
CreateTimer("Tile.7","flipthem", 500);


This would trigger the first Tile's timer. Then add an ontimer event to this tile and put this code in:
Code: Select all
animpos+=1;
CreateTimer("Tile.8","flipthem",500);
DestroyTimer("flipthem");



This would roll the animation one position, Create a new timer for the next tile, kill the timer that created tile.7's roll. Then just do the same till you get to the last tile where you wouldn't need to do the CreateTimer event(line 2).

PostPosted: Sat Jul 07, 2007 5:19 pm
by DocRabbit
Ok,

I have an example for you now. Use something similar to this in the event you want to start the animpos change.
Code: Select all
SendActivationEvent("Tile.7");


Now with Tile selected, click add event button and select activation event.
For the from actor, select whatever event actor started it. Now click add action button and select script editor, and put in this code. Make the timer in these sections a 1 time timer.
Code: Select all
getclone("Tile.7")->animpos+=1;
CreateTimer("Event Actor", "pausetimer", 500);


Now, right-click on Tile.7 actor, and click on New Activation Event. Then Timer, and select your pausetimer. Click on Choose Actor button, and click on Tile.8. hit esc key to exit out of selecting.
Now with Tile selected, click add event button and select activation event.
For the from actor, select Tile.7(you will need to click + next to Tile to select it). Now click add action button and select script editor, and use this code.
Code: Select all
getclone("Tile.8")->animpos+=1;
DestroyTimer("pausetimer");
CreateTimer("Event Actor", "pausetimer2", 500);


continue to Tile.9 with similar code, and when you get to the Last Tile you want to trigger, remove the CreatTimer from the code.

You can create a different timer for each activation link. ie pausetimer,pausetimer2,etc. as code shows. or use the same one, your choice.