Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: manny.p on Mon 20/06/2005 00:33:17

Title: Alternative to wait? (i want something to loop before going onto the next func)
Post by: manny.p on Mon 20/06/2005 00:33:17
Hi this is in my rep_ex:
if (IsTimerExpired(2)==1) {
SetTimer(2, 12);
object[0].SetPosition(object[0].X-1,object[0].Y);



And this is in my after fadein:
SetTimer(2, 12);
Wait(400);
object[1].IgnoreWalkbehinds = 1;
object[1].Visible=true;


Now i want SetTimer 2 function to continue throughout the script even when it waits 400 cycles before the next function processes, but it stops as soon as i put that Wait in there so how can i change the code?
Title: Re: Alternative to wait? (i want something to loop before going onto the next fu
Post by: Ashen on Mon 20/06/2005 00:51:24
Use rep_ex_always, maybe? (Will need to create it yourself.) I think that keeps processing when the game is Waiting.

Otherwise - what do you want to happen? There may be another way to achieve it.

Oh, and I'm fairly sure you can use object[0].X --; instead of object[0].SetPosition(object[0].X-1,object[0].Y);. Absolutely no difference, just quicker to type.
Title: Re: Alternative to wait? (i want something to loop before going onto the next fu
Post by: manny.p on Mon 20/06/2005 01:36:32
I'm a n00b at scripting, you'r gonna have to tell me how make that rep_ex_always

The reason i want this is because i want the clouds (object 0) to continue moving from it's position to the left while other objects appear and disappear (object.visible).
Title: Re: Alternative to wait? (i want something to loop before going onto the next fu
Post by: monkey0506 on Mon 20/06/2005 06:07:45
function repeatedly_execute_always() {
  /* you can't call blocking scripts within this function! */
  /* leave your other scripts the way they are, except remove the "SetTimer(2, 12);" line from after fade-in, and the "if (IsTimerExpired(2)==1)" block from rep_ex */
  if (IsTimerExpired(2)) { /* == 1 is optional in this case; it is passed as true if it is 1 */
    SetTimer(2, 12);
    object[0].X--; /* like Ashen said, a lot easier to write */
    }
  else SetTimer(2, 12);
  }

Actually, in this case the timer shouldn't ever expire...I'm not quite sure what you're trying to do (I'm kind of tired), but I hope this helps you figure it out.
Title: Re: Alternative to wait? (i want something to loop before going onto the next fu
Post by: Ashen on Mon 20/06/2005 10:21:41
Actually, you need to leave the SetTimer (2,12) in 'after fade-in', and remove that else SetTimer(2,12); from rep_ex_always - the way it is now the timer will be constantly restarted, and never get a chance to expire (as monkey said).

And it goes in the room script, in case you were wondering -  just make sure it's outside all existing functions.

To clarify, your room script should look something like:

//room script file

function repeatedly_execute_always() {
  /* you can't call blocking scripts within this function! */
  if (IsTimerExpired(2)) { // the '==1' is optional in this case
    SetTimer(2, 12);
    object[0].X--;
  }
}

#sectionstart room_a  // DO NOT EDIT OR REMOVE THIS LINE
function room_a() {
  // script for room: Player enter room (after fade-in)
  SetTimer(2, 12);
  Wait(400);
  object[1].IgnoreWalkbehinds = 1;
  object[1].Visible=true;
}
#sectionend room_a  // DO NOT EDIT OR REMOVE THIS LINE

// Rest of room script ..........


('after fade-in' doesn't might not be room_a - they're labled in the order you create them. Just make sure the script cont ent is right.)
Title: Re: Alternative to wait? (i want something to loop before going onto the next func)
Post by: Gilbert on Mon 20/06/2005 10:29:33
You can only do stuff like declaring variables or static variable defining outside of functions. maybe you're talking about functions that run only once? :=

/me is tired too, so He didn't read all of this thread.
Title: Re: Alternative to wait? (i want something to loop before going onto the next fu
Post by: manny.p on Mon 20/06/2005 12:36:12
hi thnx all, you solved my riddle, now i have an exact monkey island intro replica!

I got 2 more questions which i think are only possible in my imagination:

1. Change the background using a function?
Could i possibly make and animation backgrounds which loads the second frame when i ask it to using a funcion?

2. Instant room change, no transition effect?
FadeIn(60); doesn't work because character[EGO].ChangeRoom(1); is it's own function (you know what i mean), it there a way for a character to change the room without that transition effect?
Title: Re: Alternative to wait? (i want something to loop before going onto the next fu
Post by: strazer on Mon 20/06/2005 13:12:32
1.) You can set the background to animate by adding background frames to the room, then use SetBackgroundFrame(0); in "Player enters screen (before fadein)" to pause the animation at the specified frame and finally use SetBackgroundFrame(-1); to start the animation.

If you need different delays for each frame, check out this thread (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=20702.msg252549#msg252549).

2.) You can change the transition behaviour in the General settings pane, but if you only need it for one particular situation, you can do this:


  SetNextScreenTransition(eTransitionInstant);
  player.ChangeRoom(1);