Home   Help Search Login Register  

Author Topic: Results of spawn (to execute function)  (Read 2943 times)

0 Members and 1 Guest are viewing this topic.

Offline ModestNovice

  • Members
  • *
Results of spawn (to execute function)
« 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?
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Results of spawn (to execute function)
« Reply #1 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 which can also be the cause for the scrambled number order.
« Last Edit: 06 Sep 2012, 07:33:58 by h- »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline ModestNovice

  • Members
  • *
Re: Results of spawn (to execute function)
« Reply #2 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.
« Last Edit: 06 Sep 2012, 19:10:52 by ModestNovice »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley