How to do an infinite loop in a cutscene?

Started by ElectricMonk, Sun 04/04/2004 21:29:13

Previous topic - Next topic

ElectricMonk

Hi all,

I'm trying to put an animated cutscene near the end of my game. It contains an object moving around, and an animated view of the character reacting to the object.
I want this cutscene to loop until a key is pressed, and then proceed to another room, which will contain the "congratulations, you won" message.

To make the loop infinite, I thought I'd use a "while" function checking on something that will never happen.

But as soon as I click the mouse now, the game freezes completely and can only be quit by going the CTRL+ALT+DEL route.

Could anyone tell me the official and non-freezing way to make an infinite loop?
Thanks...

Just for reference, here's the script:
Quote
// room script file

function doanimation()
{
SetObjectView(0, 10);
AnimateObject(0,0,0,0);
Wait(25);
ObjectOn(1);
MoveObjectDirect(1,267,35,4);
while (IsObjectMoving(1)) Wait(1);
MoveObjectDirect(1,267,52,4);
while (IsObjectMoving(1)) Wait(1);
MoveObjectDirect(1,267,215,4);
while (IsObjectMoving(1)) Wait(1);
PlaySound(4);
MoveObjectDirect(1,217,173,4);
while (IsObjectMoving(1)) Wait(1);
MoveObjectDirect(1,154,215,4);
while (IsObjectMoving(1)) Wait(1);
PlaySound(5);
MoveObjectDirect(1,110,190,4);
while (IsObjectMoving(1)) Wait(1);
ObjectOff(1);
}

function room_a() {
 // script for room: First time player enters screen

StartCutscene(4);
{
while (GetGlobalInt(30) !=42) // which it will never reach, since it's only ever 1 or 0 in the game...
doanimation();
}
EndCutscene();
NewRoom(11);
}

Scummbuddy

I know you could do something like this:
------------------------
 if (my_counter == 0) {
   {{Put in here the object moving code))
 }
 if (my_counter == 10000) {
   {{put in here the call to go to the new room }}
 }
    if (my_counter < 10000) {
   my_counter += 1;
 }
--------------------------------

but this isn't sooo "infinite" but i dont think anyone will stick around to wait that long.

im sure there is another way, but its too tired for me to think right now.  I'll rethink it tomorrow.
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

ElectricMonk

Heh :)
I thought of something like that, but there has to be a way to make an infinite loop without crashing the computer...

Maybe checking the "repeatedly execute" function for a flag that gets set to 1 when the animation ends and to 0 when it starts or something...

Gilbert

#3
As far as I remember, there're some limit on number of loops executed for AGS to avoid infinite loop freezings, so I think you can do infinite loops just with while.

Just do whatever you suggested (the setting a variable and repeatedly execute method) for an "infinite" loop.


Scorpiorus

When you press a key to skip a cutscene AGS runs the script at full speeds untill it reachs EndCutscene() function. But since the while's condition is always true it will never get to it (so we get infinite loop here).

To avoid this you need modify the script a bit, like:

int interrupted = 0;
while (interrupted == 0) {
   StartCutscene(4);
   doanimation();
   interrupted = EndCutscene();
}
NewRoom(11);

or without using of extra variable (actually the same):

StartCutscene(4);
while (EndCutscene()==0) {
   StartCutscene(4);
   doanimation();
}
NewRoom(11);

~Cheers

Hollister Man

I honestly don't understand or use the Cutscene commands myself.  

Set a flag, say int mouseclick=0

when you start the loop set mouseclick=1;

now in your room rep_ex you make your loop, and check for the mouse click.  when that occurs, set the flag back to zero, or to -1 to stop the loop and move to NewRoom()

Don't have time to script it now, but you shoudl get the picture.
That's like looking through a microscope at a bacterial culture and seeing a THOUSAND DANCING HAMSTERS!

Your whole planet is gonna blow up!  Your whole DAMN planet...

ElectricMonk

#6
I think I did something like that (I replaced every "Wait(1)" with a function that checks for a mouseclick and on click goes to another room, otherwise waits 1), and when I did click the mouse I got an error. I don't exactly recall it, but the program accused me of calling two "NewRoom" commands when only one was allowed or something... I'll have to try and replicate the error and post the script...

EDIT:
Never mind. Thank you Scorpiorus, your suggestion worked! :D :D :D

SMF spam blocked by CleanTalk