C++ Question How to loop a warning light?

fausto

FOI SuperMod
Joined
Jul 13, 2008
Messages
797
Reaction score
2
Points
0
Location
Monza (Milan)
I created an animation that switch on a warning light when the Fuel Mass is below a critical value.. i want this animation to repeat until the fuel mass is critical.. i suppose i have to create a loop by using "while"..

Code:
while(FuelkMass<=35)
{
RevertMasterAlarm();
}

..but i have a CTD..
I wrote these lines in clbkprestep..
any suggestion?
 

Moach

Crazy dude with a rocket
Addon Developer
Joined
Aug 6, 2008
Messages
1,581
Reaction score
62
Points
63
Location
Vancouver, BC
well, my friend, seems you've bought yourself an infinite loop...

if you use "while" your code will loop unyieldingly at that position - stopping orbiter from doing other things - things such as, well... altering your fuel level - which as you have set it, seems to be the only way out of your loop....


hence, an impossible situation - the infinite loop...


that function is already being called once every frame - remove the while block and you should see your light blink REALLY fast...

then consider the fact that it's blinking once per frame... that's about 60 times per second (provided you got enough computer to make that FPS)

either way - you should still think about slowing it down, so i suggest something like this:
Code:
static int blinkTimer = 0; // static means this number will be preserved between function calls (sets to zero only once)
blinkTimer += simdt; // add delta-time to your timer
if(FuelkMass<=35 && blinkTimer > 500) // 500 ms (blinks on and off every second)
{
     RevertMasterAlarm(); // toggle your lamp
     blinkTimer = 0; // reset timer
}


see if that helps :thumbup:
 
Last edited:

RisingFury

OBSP developer
Addon Developer
Joined
Aug 15, 2008
Messages
6,427
Reaction score
492
Points
173
Location
Among bits and Bytes...
It's interesting that you got a CTD in this case, assuming RevertMasterAlarm() has no errors.

I had an infinite loop somewhere when I was rewriting the instruction queue for the OBSP autopilot and my Orbiter just froze...
 

jthill

Member
Joined
Apr 10, 2010
Messages
99
Reaction score
0
Points
6
Would putting a vessel beacon inside the cockpit work?
 

fausto

FOI SuperMod
Joined
Jul 13, 2008
Messages
797
Reaction score
2
Points
0
Location
Monza (Milan)
Thank you for your quick reply!
still not working.. take in account that RevertMasterAlarm() is an animation sequence, which translate a button down and up 2 times!
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,659
Reaction score
2,379
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
still not working.. take in account that RevertMasterAlarm() is an animation sequence, which translate a button down and up 2 times!

Then calculate the state of the animation in PostStep as function of the simulation time or the real system time. For example as sinus or sawtooth function.
 
Top