Jump to content

Recommended Posts

Hello guys! Please could you clarify some of the my assumptions about triggers, I'm newbie at scripting.

 

I have a AI soldier (dummy1), who cycling around with WP's, and a trigger, with something like this

 

trigger1 / Any Player / Present

 

On Activation:

animCondition = true;
0 = [dummy1, "Acts_A_M01_briefing", animCondition] spawn anim_fnc_loopAnimation;

On Deactivation:

animCondition = false;
dummy1 switchMove "";

 

and simple function anim_fnc_loopAnimation, which waits for public animCondition to break the loop, which defined in misson namespace, (or in init.sqf, doesn't matter in this case)

 

_unit = _this select 0;
_animation = _this select 1;

while { animCondition } do
    {
        _unit switchMove _animation;
        waitUntil { animationState _unit != _animation };
    };

The question, Am I right, that triggers executes in un-schedule environment , but with spawn, anim_fnc_loopAnimation will executed in scheduled environment?
But if I use call anim_fnc_loopAnimation it will be executed in un-scheduled environment AND while loop will breaks after 10K iterations? It will exit the loop or the function itself?

Share this post


Link to post
Share on other sites

I've  read the 10k thing many times but I just ran a test doing a count  and it went well above 10k  before I terminated  the script.

In all my years of scripting I've never had an issue with a while loop terminating unexpectedly.

Share this post


Link to post
Share on other sites

Spawned or execVM'd while loops can run forever. Called while loops terminate after 10K iterations.

Share this post


Link to post
Share on other sites
7 hours ago, Harzach said:

Spawned or execVM'd while loops can run forever. While loops in code called from an unscheduled scope terminate after 10K iterations.

Just thought I would make that distinction. The command call has no effect on whether the called code is unscheduled of not, it is the state of the scope the call happens from that is transferred to the new scope. So if the call happens from an unscheduled scope the called code is unscheduled and visa versa.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks @Larrow, I managed to remember the tidbit I posted from KK's blog, but not that important distinction.

 

Here's the relevant text and a link:
 

Quote

The limit is set in place for when the script is called by the engine and it has to wait for call to return before it can do other things. This happens when you call the infinite while loop from either event handler, FSM script or init line. If your script is executed using spawn or execVM, you can make whileloop run forever. Also the aforementioned examples of infinite for loop construct is entirely free of this limitation. By the way init.sqf file is not called so the while true loop in it will run forever. 

 

http://killzonekid.com/arma-scripting-tutorials-loops/

  • Like 1

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

×