Flickering background animation (problem script related)

Started by Hollister Man, Fri 16/04/2004 20:53:01

Previous topic - Next topic

Hollister Man

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Ã, 
Code: ags
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.
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...

Kweepa

#1
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:

Code: ags

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?
Still waiting for Purity of the Surf II

Hollister Man

[ 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!
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...

Gilbert

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:


Code: ags
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++; 
}


Hollister Man

thanks!  I think that just might work.  I'll give it a try after work.
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...

Hollister Man

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.
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...

SMF spam blocked by CleanTalk