Jump to content
Sign in to follow this  
Holden93

How to check a condition after time without the need of waitUntil or a loop?

Recommended Posts

Maybe the title is a little bit confusing, just an example down here:

if(!(alive gunner1 || alive gunner2)) then 
  _x sideChat "One gunner is down! We need someone else on the HMG!";

So, if I'm right that condition should be checked as soon as the script is triggered, is there a way to, let's say check if it's true or false every frame and stop the game from checking it when the part of the mission where it's needed is done? As I said in the title without using a while loop or waitUntil, not because I don't like them but for optimization purpose.

EDIT: Does the "rule" of the no brackets needed when there's only one string of code after the condition/loop apply to Arma?

Share this post


Link to post
Share on other sites

A trigger ;)

A waituntill will execute only once when it's condition is met unless it's inside a loop or the script is called again. If you want anything to run only while it's needed in the mission then you need to add another "if" and break out of the loop when the condition is met, such as a boolean set to true when an objective is complete...

Checking a condition once per frame is more resource intensive but if you need it then use onEachFrame https://community.bistudio.com/wiki/onEachFrame and/or stacked event handlers. This would run in the core none-scheduled environment btw.

Generally you should use triggers (none-scheduled environment) or loops/waitUntils with sleeps (scheduled environment) where you can, to save cpu ponies and allow other scheduled stuff to breath.

---------- Post added at 20:22 ---------- Previous post was at 20:21 ----------

EDIT: Does the "rule" of the no brackets needed when there's only one string of code after the condition/loop apply to Arma?

Nope..

Share this post


Link to post
Share on other sites

What does a stacked event handler actually do?

Also you could use an eventhandler

gunner unit addMPEventHandler ["MPKilled",{player sideChat "One gunner is down! We need someone else on the HMG!"}];

Share this post


Link to post
Share on other sites

I've barely used eventhandlers myself yet, but from what I've understood is that if you use multiple onEachFrames added as a stacked event handler via BIS_fnc_addStackedEventHandler it creates only one instance of the handler, and adds everything as function calls in that one instance of the event handler.

If you use them none-stacked, ie not via BIS_fnc_addStackedEventHandler, then it creates a new instance of each event handler. I guess it affects performance among other things I don't know or understand yet.

Share this post


Link to post
Share on other sites

Cheers I'll have to have a play with it some time.

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  

×