Jump to content
Sign in to follow this  
mdraimund

Passing arguments to spawn

Recommended Posts

Hello everyone,

Having some trouble getting arguments to be passed to a spawn code. The following code is meant to make sure all scripts are being executed properly. I pass the script to the spawn code as an argument but it returns <Null-script>. Has anyone got some insight?

_scriptHandle = [] execVM "script.sqf";

[_scriptHandle] spawn {
private ["_script", "_debug"];
_script = _this select 0;
_debug = str (_this select 0);
sleep 5;
if (!scriptdone _script) exitwith {hint format["Debug %1", _debug];};
};

Share this post


Link to post
Share on other sites

Its a feature not a bug.

If you read the wiki here look at the bottom of the page.

A Null Script handle can be created in this manner:

_handle = 0 spawn {};

That is what any Script_(Handle) becomes when a script is finished running, meaning it will test as true with: scriptDone _handle and it returns "<NULL-script>" when converted to string. This in turn lets you initialize the variable with a completed Script_(Handle) and lets you test the variable even though nothing else may have set the handle by creating a script with spawn orexecVM. It also lets you store and manage script handles in arrays, and a few other sexy things.

Share this post


Link to post
Share on other sites

Allright, so this could mean that the script is already done by the time the spawn script makes a string out of the argument? So unless anyone can see any errors in my code I'll happily go on believing this actually works.

Share this post


Link to post
Share on other sites

I'm not entirely sure what you're trying to do. What do you mean with "executed properly"? That it has finished running? For that you could use

 _handle = [] execVM "script.sqf";
 waitUntil {scriptDone _handle};

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  

×