Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Kinoko on Wed 04/02/2004 00:33:20

Title: Animated background code being blocked
Post by: Kinoko on Wed 04/02/2004 00:33:20
I've been posting this in the beginners forum up until now but I thought I'd see if I could get any more help from here before I went ahead and did much more.

Basically, I wanted to create an animated background controlling the delays between each frame. Gilbot helped me with that code and it works fine on it's own. Here for referance:

1. put on top of that room's script:
int bgtimer,curbg;
int bgdelay[3];

2. Put in "first time player enters screen" script:
bgdelay[ 0 ]=8;
bgdelay[1]=10;
bgdelay[2]=7;
curbg=0;
SetBackgroundFrame(curbg);
bgtimer=bgdelay[curbg];

3. Put in "repeatedly execute" script:
bgtimer--;
if (bgtimer==0) {
curbg++;
if (curbg>2) curbg=0;
SetBackgroundFrame(curbg);
bgtimer=bgdelay[curbg];
}


The only problem is that, as the room in question is used only in a short cutscene, I have some blocking functions in there such as Wait, DisplaySpeech etc. One suggestion was to use this:

int waitimer=100;
while (waitimer){
Wait(1);
room_b(); //change it if your repeatedly execute script is not of this name
waitimer--;
}


instead of Wait(100); and that worked but before I do that for every single function in that room, does anyone have any other ideas as to how I can continue to have my background animated regardless of other blocking functions?

Thanks.
Title: Re:Animated background code being blocked
Post by: Gilbert on Wed 04/02/2004 01:44:33
Unfortunately, it seems that blocking functions will block all other scripts from running, so you need to use non-blocking functions for it, for example, use DisplaySpeechBackground() instead of DisplaySpeech().

For example:
DisplaySpeech(EGO, "blah!");

can be changed to:
waitimer=150; //Unfortunately you have to work out the delays yourself
int handle;
handle=DisplaySpeechBackground(EGO, "blah");
while (waitimer){
Wait(1);
room_b(); //change it if your repeatedly execute script is not of this name
waitimer--;
}
If (IsOverlayValid (handle)) RemoveOverlay(handle);


Worst of all, the talking animations won't be played with DisplaySpeechBackground(), so you may add even more codes to animate him.
Title: Re:Animated background code being blocked
Post by: Kinoko on Wed 04/02/2004 10:45:53
Luckily I don't have to worry about speech animation for this scene.

OK, I think it's all looking fine except I'm getting an "Undefined token "If"" for that:
If (IsOverlayValid (handle)) RemoveOverlay(handle);
line...

EDIT: Oh, ok. Nevermind, I just figured out what that means ^^ If -> if ... problem solved!

THANKYOU person with the great nickname that seems to indicate an interest in the ever wonderful Futurama. It finally works perfectly! @_@
Title: Re:Animated background code being blocked
Post by: Gilbert on Wed 04/02/2004 11:10:32
Ah yeah a case mistake, sorry about that.

Heh actually I'd never watched Futurama and don't know much about it (except for that it looks really much like Simpsons), that must be a coincident. ;)
Title: Re:Animated background code being blocked
Post by: Kinoko on Wed 04/02/2004 12:42:52
Oh, you should watch it. It's very awesome. But I'm getting off-topic now so I'll shut up ^_-
Title: Re:Animated background code being blocked
Post by: Pumaman on Sat 07/02/2004 12:25:08
You don't actually have to paste that code in everywhere, though. You could write your own Wait, function, like this:

function MyWait(int waittimer) {
while (waitimer){
Wait(1);
room_b(); //change it if your repeatedly execute script is not of this name
waitimer--;
}
}

and then just call  MyWait(100);  from your other scripts.