Jump to content
Sign in to follow this  
Murklor

Strangeness with a simple if

Recommended Posts

Its very simple. I have an eventhandler reacting to the state of the engine in a LAV HQ vehicle. Then a short file that does this, just to test out the event handler:

_mhq = _this select 0;
hint format["isengineon: %1", isengineOn _mhq];
if (isengineOn _mhq) then {
_mhq sideChat "Engine is on"; 
};

Its nothing strange when you turn the engine on, it reports true and chat that the engine is on. But when you turn the engine off via the action menu, it reports false BUT STILL CHAT THAT THE ENGINE IS ON!

How is that even possible? :confused:

Even stranger is that if you get out of the vehicle (instead of just turn the engine off), it reports false and doesnt chat (ie proper behaviour). Am I just missing something blatantly obvious on kindergarten coding level? :o

Share this post


Link to post
Share on other sites

Could be result of using isEngineOn at the time of engine state change. Assuming you're using an engine EH, use _this select 1 instead to get the engine status.

Share this post


Link to post
Share on other sites

Empty

Edited by Dan86
Mismach in thread quest

Share this post


Link to post
Share on other sites

Dan, first of all, it's not nice to hijack someone elses thread.

Second, your script is all fubar because you're using a mix of sqs and sqf syntax. I suggest you check out the Wiki and learn the differences between sqf and sqs syntaxes.

Share this post


Link to post
Share on other sites
Could be result of using isEngineOn at the time of engine state change. Assuming you're using an engine EH, use _this select 1 instead to get the engine status.

I dont quite get what you mean... the engine state has obviously already changed when you turn off the engine from the action menu as the hint says its false. Yet the if statement think its true. I'll try the select 1 and see how that works... And for a laugh I might try storing the isengineon in another variable, see what happens when one if that lol.

Edit: nope. I tried this

_mhq = _this select 0;
_mhqenginestate = _this select 1;
hint format["Engine state: %1", _mhqenginestate];

if (_mhqenginestate) then {
_mhq sideChat "Engine is on"; 
};

And it displays the exact same behaviour as before. _mhqenginestate has the proper value in all cases, true when engaging the engine and false when disengaging (regardless of turning off it from the action menu or using get out). Yet the if statement completely ignores what _mhqenginestate is turning off the engine from the action menu and somehow transform the false to true on its own.

Something even stranger was that I noticed the game completely ignoring /* and */... Isnt that supposed to work with sqf?

Edited by Murklor

Share this post


Link to post
Share on other sites

Oeps, didnt know i will "hijack thread", tought is a good place to give some more "IF" questions.Gonna clean it up...

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×