OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: ModestNovice on 06 Sep 2012, 02:03:51

Title: Results of spawn (to execute function)
Post by: ModestNovice on 06 Sep 2012, 02:03:51
With a function of mine, I tested with:
Code: [Select]
for "_i" from 1 to 15 do
{
     [format["test %1", _i]] spawn function;
};

The function shows a hint, but the order of the numbers would be scrambled. I believe this is because spawn runs the script in parallel. When I added sleep 0.1, the numbers showed in order. Is there a way to ensure the function spits everything out in the correct order?
Title: Re: Results of spawn (to execute function)
Post by: h- on 06 Sep 2012, 07:32:06
Why would you use spawn in the first place?
It's pretty much the same as execVM, apart from being able to execute preprocessed code, not meant for running functions that return value but the same kind of scripts as execVM.
For functions use call instead.

A2 also has the (very annoying) scheduler for scripts (http://rte.jonasscholz.de/blog/2009/10/02/new-to-arma-2-threads) which can also be the cause for the scrambled number order.
Title: Re: Results of spawn (to execute function)
Post by: ModestNovice on 06 Sep 2012, 19:08:12
Not sure, I'm not a whiz with coding. The function does not return anything, so I figured I would just use spawn. I'll change them to call instead. Interesting about the script scheduling, it rather confuses me. Thank you for the advice.