Jump to content
Sign in to follow this  
Wolfenswan

Trigger vs. Loop (w. Sleep) - which yields better Perfomance?

Recommended Posts

To my knowledge a Trigger checks it's condition every frame (x frames).

So, in theory, a loop that only checks the same condition every x seconds due to an included sleep should provide better performance.

Am I correct in this or is for some reason a trigger still the more economical solution?

To illustrate my question a bit better:

1. A script creates a set of units, randomly.

2. Each of these units should perform a certain action once a unit of type X gets lose.

2a. Have the script create a trigger and attach it to the Unit with the correct condition.

2b. Have the script start a while {alive _unit} loop with sleep 1 that repeatedly checks if the condition is fulfilled.

Thanks.

Share this post


Link to post
Share on other sites

A trigger checks its condition twice per second. That is every 0.5 seconds. So no problem using a trigger. If you want to check more often, or less often you would need to use a script with the appropriate sleep.

Basically this is how the trigger works:

waitUntil {sleep 0.5; <CONDITION-CODE>};

<ACTIVATION-CODE>

A repeatable trigger kinda works like this:

while {true} do {
 waitUntil {sleep 0.5; <CONDITION-CODE>};
 <ACTIVATION-CODE>
 waitUntil {sleep 0.5; not <CONDITION-CODE>};
};

I didn't include the timeouts/countdown, or deactivation here. But that is a pretty good approximation of how triggers would be, if they were sqf.

Share this post


Link to post
Share on other sites

Triggers run in a non-scheduled enviroment, waitUntil / sleep commands do not. That's the main difference. After that it pretty much boils down to what the activation code is and how long it takes to execute, that's my understanding.

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  

×