Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AddTimer infinite loop (fixed) :)
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#2
RE: AddTimer infinite loop problem :(

Dear lord, you sure did that script the long way. XD

There's probably some spelling error you're overlooking, but what makes it hard to notice is the fact that you're doing in over 100 lines what you could be doing in maybe 15.

Try using a local variable to track which step in the entire lightning event you're at, essentially which "bang" is occurring. This way you can use a single timer function to loop itself, and once the variable reaches a certain point (in this case, 9) you can just stop the loop. I'll write it out so you can see how it'll work:


NOTE: Don't use this script until you've opened your map in Amnesia. I haven't tested it so I might have put a spelling error or some other error. Open your map, then paste this script in and see if it works for you. If you have any questions about how the script I wrote works, feel free to ask

PHP Code: (Select All)
// stating the step, start at 0 so first repetition runs step 1
int BANG_STEP=0;
// should the loop continue?
bool bCONTINUE_LIGHTNING=true;

void BANG_LIGHTNING(string &in timer)
{
    
    
// add 1 to the event step
    
BANG_STEP++;
    
    
// if last bang occurred, break the loop
    
if(BANG_STEP==9bCONTINUE_LIGHTNING=false
    
    
// turn the lights on!
    
BANG_LIGHTS_ON(BANG_STEP);
}

// this is a float array - contains timer durations for pauses between lights on/off at each bang step
const float[] fPAUSE_VALUES={    0.25f0.35f0.37f,
                                
0.27f0.38f0.4f,
                                
0.19f0.33f0.28f
};

void BANG_LIGHTS_ON(int BANG_STEP)
{
    
// turn the lights on
    
for(int i=1;i<=23;i++) SetLightVisible("thunder"+itrue);
    
    
// wait a specific duration (unique to each ban step) until turning hte lights off
    
AddTimer(""fPAUSE_VALUES[BANG_STEP], "BANG_LIGHTS_OFF");
}

void BANG_LIGHTS_OFF(string &in timer)
{
    
// turn the lights off
    
for(int i=1;i<=23;i++) SetLightVisible("thunder"+ifalse);
    
    
// if not last lightning step, wait a random duration to play the next lightning bang
    
if(bCONTINUE_LIGHTNINGAddTimer(timerRandFloat(45.0f70.0f), timer);


(This post was last modified: 01-01-2012, 02:20 AM by palistov.)
12-31-2011, 09:45 PM
Find


Messages In This Thread
AddTimer infinite loop (fixed) :) - by jssjr90 - 12-31-2011, 10:54 AM
RE: AddTimer infinite loop problem :( - by palistov - 12-31-2011, 09:45 PM



Users browsing this thread: 1 Guest(s)