Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: CB.. on Mon 27/10/2003 00:16:33

Title: is it possible to repeat a script every 5 seconds
Post by: CB.. on Mon 27/10/2003 00:16:33
i have a move character script which i want to repeat every five seconds ,
but if i place it in the repeatedly execute section it trys to execute the script every nano second ,not gving the character time to exexcute the movement before it restarts the timer...if i use wait so it completes the movement before it restarts ,then the player gets stuck in wait mode (because the script is in repeatedly execute etc)
im stuck in a bit of a catch twenty two loop here im afraid!

this would be wonderfull for populating towns with randomly moving characters that actually have a life of their own...

this is the script

SetTimer(1,200);
if (IsTimerExpired(1)==1)
{int ran=Random(7);
if (ran==0) MoveCharacter(GDTWO,character[GDTWO].x-36,character[GDTWO].y);
else if (ran==1) MoveCharacter(GDTWO,character[GDTWO].x+34,character[GDTWO].y);
else if (ran==2) MoveCharacter(GDTWO,character[GDTWO].x,character[GDTWO].y-36);
else if (ran==3) MoveCharacter(GD,character[GD].x+34,character[GD].y);
else if (ran==4) MoveCharacter(GD,character[GD].x,character[GD].y-36);
else if (ran==5)MoveCharacter(GD,character[GD].x,character[GD].y+36);
else MoveCharacter(GDTWO,character[GDTWO].x,character[GDTWO].y+36);
}

i can set it with a lot of regions and have it run as a walk on walk of region run script appraoch but this just isnt satisfying enough and very untidy..with a repeat/loop command it would simply take care of itself

(for example im using it in the escape from colditz game for two gaurds searching for the player as he trys to escape across some fields..)

if there is an easy way to ad a simple loop command to the scripting of movements etc then with all the possible
if
else if's available in the editor some sort of developing AI behaviuor could develop...for instance if a player has an inventory item this can be added into the else ifs and change the behaviuor of the characters  and so on...please tell me its just a matter of adding asome sort of loop command at the end of it!!  
Title: Re:is it possible to repeat a script every 5 seconds
Post by: Timosity on Mon 27/10/2003 03:42:20
I did something similar in a room for characters walking randomly like this:

first at top of room

int startwalk=0; // initiates the characters walking in the repeatedly execute

then I set 3 timers in  // script for room: Player enters screen (before fadein)

SetTimer(1,300);
SetTimer(2,800);
SetTimer(3,1200);

then

 // script for room: Repeatedly execute
if (startwalk==0){ //for random people walking

if (IsTimerExpired(1)==1){
ranwalk(); // function for the random walking
startwalk=1; // for next stage
}
}


if (startwalk==1){

if (IsTimerExpired(2)==1){
ranwalk(); // function for the random walking
startwalk=2; // for next stage
}
}


if (startwalk==2){

if (IsTimerExpired(3)==1){
ranwalk(); // function for the random walking

SetTimer(1,300);
SetTimer(2,800);
SetTimer(3,1200);

startwalk=0); // take back to start
}
}


This works fine, note: I was moving 3 different characters randomly and at slightly different time intervals,
I think you need to break up your repeatedly execute into sections like I've done above, so it actually starts the timer ticking over again.

That's the way I got it to work anyway.

Hope it helps in some way.

~Tim
Title: Re:is it possible to repeat a script every 5 seconds
Post by: CB.. on Mon 27/10/2003 11:21:17
ok many thanks!
am studying it;  breaking the timer trigger into cascading sections sounds about right

be nice if there was a

SetTimerEx

for a simple repeat option

yu got me thinking many thanks...(i was worried i was mising somthing simple in the reference manual on repeating scripts)

i got to take the settimer out of the repeatedly execute or give it extra triggers to prevent it running every cycle..and place the set timer in the room start then have an extra trigger for it (have i got that right)
brain wave!! perhaps if i set the characters idle animation to set the timer then it might be self contained?
ill go and have an experiment...all good stuff many thanks for the inspiration..!!
got to say that  AGS is a great hobby in it self!
many thanks !



OK got it!!!!


in repeatedly execute;



if (IsTimerExpired(1)==1)
{int ran=Random(7);
if (ran==0) MoveCharacter(GDTWO,character[GDTWO].x-36,character[GDTWO].y);
else if (ran==1) MoveCharacter(GDTWO,character[GDTWO].x+34,character[GDTWO].y);
else if (ran==2) MoveCharacter(GDTWO,character[GDTWO].x,character[GDTWO].y-36);
else if (ran==3) MoveCharacter(GD,character[GD].x+34,character[GD].y);
else if (ran==4) MoveCharacter(GD,character[GD].x,character[GD].y-36);
else if (ran==5)MoveCharacter(GD,character[GD].x,character[GD].y+36);
else MoveCharacter(GDTWO,character[GDTWO].x,character[GDTWO].y+36);
SetTimer(1,200);
}  




then this in enters room after fade in



SetTimer(1,200);




nice one!!!