The Dink Network

Two loops at the same time

March 29th 2010, 01:15 PM
dragon.gif
Quiztis
Peasant He/Him Sweden bloop
Life? What's that? Can I download it?! 
Is there some clever way to have two loops (kinda) going on at the same time? Example: While the wizard walks a fixed path he shoots fireballs every five seconds.
March 29th 2010, 02:39 PM
slimeg.gif
metatarasal
Bard He/Him Netherlands
I object 
Sure, just make sure that both loops are in different scripts.

Something like this:

Wizard's script:

void main(void)
{
&global = &current_sprite;
spawn("fireloop");
loop:
move_stop(&current_sprite,4,x,1);
move_stop(&current_sprite,6,x,1);
goto loop;
}


Fireloop.c:

void main(void)
{
script_attach(0);
int &wizx;
int &wizy;
int &sprite;
loop:
&wizx = sp_x(&global,-1);
&wizy = sp_y(&global,-1);
&sprite = create_sprite(&wizx,&wizy,brain,seq,frame);
//Fire fireball
goto loop;
}


Note: scripts have not been tested, use at own risk.
EDIT: Also, there are ways of doing this without using a global variable, but generally I use some 'general purpose globals' that can be used whenever I feel like it on a specific screen.
March 29th 2010, 05:21 PM
dragon.gif
Quiztis
Peasant He/Him Sweden bloop
Life? What's that? Can I download it?! 
Ey, works like a charm now. Thanks.