Efficient DELAY command needed

Non-platform specific questions.

Efficient DELAY command needed

Postby akhad » Fri Jul 06, 2007 6:15 am

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?
User avatar
akhad
 
Posts: 43
Joined: Tue Jan 16, 2007 1:59 pm
Location: U.K
Score: 0 Give a positive score

Postby Fuzzy » Fri Jul 06, 2007 8:02 am

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.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby akhad » Fri Jul 06, 2007 8:54 am

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.
User avatar
akhad
 
Posts: 43
Joined: Tue Jan 16, 2007 1:59 pm
Location: U.K
Score: 0 Give a positive score

Postby Kodo » Fri Jul 06, 2007 9:24 am

If you wanted to avoid writing too much code you could do it just as easilly with timers (which are built in to GE).
Inogames: http://www.inogames.com iOS gaming
Firetop Adventure (app store): http://itunes.apple.com/us/app/firetop- ... ?mt=8&ls=1
User avatar
Kodo
 
Posts: 449
Joined: Thu Oct 20, 2005 8:20 pm
Location: UK
Score: 23 Give a positive score

Postby DocRabbit » Fri Jul 06, 2007 11:23 am

*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).
User avatar
DocRabbit
 
Posts: 114
Joined: Fri Oct 27, 2006 2:56 am
Score: 10 Give a positive score

Postby DocRabbit » Sat Jul 07, 2007 5:19 pm

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.
Attachments
SteppedTimerDemo.zip
Here is a demo to show what I mean
(404.58 KiB) Downloaded 113 times
User avatar
DocRabbit
 
Posts: 114
Joined: Fri Oct 27, 2006 2:56 am
Score: 10 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest