Jump to content
The Real Bunc

Using Params in spawned script

Recommended Posts

I've been been parameterising my DynamicCamo script so that a set of arguments are passed to the spawned script to make adjustment easier.

The spawn goes like this from a units init

 

camo = [this, "DEBUG", "aswitch", 0,1,0,1] spawn compile preprocessfile "camoscript.sqf";

 

I tried to pick up these arguments in the script itself using

params [_unit, _debug, _switch, _cLo, _cHi, _aLo, _aHi];

 

but I constantly got errors and it would not get past the first assignment ie it was throwing errors when trying to assign     this   from the spawn argument array to the  local variable _unit.

neither did the other local variables in the params line seem to be getting properly assigned.

 

But it works when in the script I do the following ;

 

_unit = _this select 0;

_debug = _this select 1;

etc.

 

I thought params was supposed to be a replacement for this more longwinded way of assigning parameter values?  I notice in the Biki for Params command that there is no

mention of using params with spawn. But it does say that it passes an array of arguments into an array of local variables in the params array. Does this not work for spawn?

Does it only work for Call or execVM ?  Or is there something wrong with my params construction?    Ive got things working using the     _this select n    approach but Id like 

to use the  params [_variable, _variable1, ….]  approach as its tidier and can include data type checks and default values.

 

Any help would be appreciated. I thought I had a handle on params but clearly I'm doing something wrong.

 

 

Share this post


Link to post
Share on other sites

Read the documentation carefully. params takes string to work.

params ["_unit", "_debug", "_switch", "_cLo", "_cHi", "_aLo", "_aHi"];

 

  • Like 1

Share this post


Link to post
Share on other sites

Params needs to be declared using strings, in your case it should be this:

 

 params ["_unit", "_debug", "_switch", "_cLo", "_cHi", "_aLo", "_aHi"]; 

If something doesn't work the way it should, always check the wiki.

 

Cheers

Share this post


Link to post
Share on other sites

Also

 

7 minutes ago, The Real Bunc said:

camo = [this, "DEBUG", "aswitch", 0,1,0,1] spawn compile preprocessfile "camoscript.sqf";

 

 

I believe this is same as (execVM):

 

camo = [this, "DEBUG", "aswitch", 0,1,0,1] execVM "camoscript.sqf";

 

  • Like 1

Share this post


Link to post
Share on other sites

Damn, I thought it was probably something simple I was missing. I must have read that Params wiki page about five times and not spotted that the params was using quotes around the variables!

Going to have another look at my script now.  Thanks for the very helpful comments guys. Ill check out execVM equivalence as well. 

Share this post


Link to post
Share on other sites
On 5/15/2019 at 4:27 PM, gc8 said:

I believe this is same as (execVM)

I think execVM might be preproc with line numbers.
But yeah it's essentially the same.

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

×