Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Hollister Man on Fri 16/04/2004 20:53:01

Title: Flickering background animation (problem script related)
Post by: Hollister Man on Fri 16/04/2004 20:53:01
I am trying to make this neon sign flicker like its really old. Ã, Basically its supposed to set a random number, count up to it, turn off the sign. Ã, Set a new random number, count up to it and turn the sign back on. Ã, For SOME reason, this won't work. Ã, Counter always == 0. ARRGGHHH!

Lets imply that all the ints and such are already declaredÃ, 
function room_c() {
Ã,  // script for room: Repeatedly execute
Ã, 
if(counter>=randsaver){
Ã,  Ã,  counter=0;
Ã,  Ã,  randsaver=Random(50);
Ã,  Ã,  SetBackgroundFrame(0);
Ã,  Ã,  flicker=Random(5);
Ã,  Ã, }
Ã,  else if(counter>=flicker){
Ã,  Ã,  counter=0;
Ã,  Ã,  flicker=0;
Ã,  Ã,  SetBackgroundFrame(1);
Ã,  Ã,  Ã, }
counter++;
}


Now, I could be just missing something.  BTW, I'd use an object, but I wanted to give a good example of "custom" animated backgrounds.
Title: Re:Flickering background animation (problem script related)
Post by: Kweepa on Sat 17/04/2004 09:21:46
When flicker hits 0, counter remains at 1

counter = 1
flicker = 0

if (counter >= randsaver) nope
else if (counter >= flicker) yup

counter = 0
flicker = 0
counter++

& repeat.

Try this instead:


int bgFrameIndex = 0;
int bgFrameTime = 0;

function room_c() {
 // script for room: Repeatedly execute
 bgFrameTime--;
 if (bgFrameTime <= 0) {
   bgFrameIndex = 1 - bgFrameIndex;
   SetBackgroundFrame(bgFrameIndex);
   if (bgFrameIndex == 0) {
     bgFrameTime = Random(5);
   }
   else {
     bgFrameTime = Random(50);
   }
 }
}


I gotta know - how do you keep tabbing in quoted code like you did?
[EDIT] Look at mine - all the code is on the left hand column. Where did the spaces go?
Title: Re:Flickering background animation (problem script related)
Post by: Hollister Man on Sat 17/04/2004 13:46:17
[ code ] and [ /code ]  inserts these boxes (and I *think* it also ignores smilies in that area, not sure)

I think I like the way your coded that, but I'm not sure I understand it.  Perhaps its cause I'm not sure its doing quite what I think it is.  I dunno, but I'll try it out when I can.  Thanks!
Title: Re:Flickering background animation (problem script related)
Post by: Gilbert on Mon 19/04/2004 04:48:05
Well, the problem is that you reset both counter and flicker to 0 everytime counter>=flicker, in the next game loop, counter will be 1, and is >=flicker again, so they're reset again, without it possible to reach randsaver again. One more problem was that the Random() function returns value from 0 to the maximum value, so my suggestion is:


function room_c() {
Ã,  // script for room: Repeatedly execute
Ã, 
if(counter>=randsaver){
Ã,  Ã,  counter=0;
Ã,  Ã,  randsaver=Random(49)+1;
Ã,  Ã,  SetBackgroundFrame(0);
Ã,  Ã,  flicker=Random(4)+1;
Ã,  Ã, }
Ã,  else if((flicker>0)&&(counter>=flicker)){
Ã,  //Ã,  counter=0;
Ã,  Ã,  flicker=0;
Ã,  Ã,  SetBackgroundFrame(1);
Ã,  Ã,  Ã, }
counter++;
}

Title: Re:Flickering background animation (problem script related)
Post by: Hollister Man on Mon 19/04/2004 15:39:22
thanks!  I think that just might work.  I'll give it a try after work.
Title: Re:Flickering background animation (problem script related)
Post by: Hollister Man on Thu 22/04/2004 04:27:39
Sorry for the couble post, but I figured it was worth a bump anyway.

Gilbot's suggestion fixed it, I guess I was just trying too many shortcuts.  I did have to switch the "on" and "off" frames, and adjust the speed for a nice effect, but that wasn't his fault.