Jump to content
Sign in to follow this  
Slapstick

Wresting with SQF syntax

Recommended Posts

I am trying to learn SQF, but as a C++/Java programmer I carry a lot of baggage and preconcieved notions and some things I see just don't make any sense.

First off, I've come across the following more than once:

0 = [] execVM "someScript.sqf";

So, WTF is up with assigning the value returned by the "someScript.sqf" script to a literal constant?

Second, I'm reading the wiki documentation for the BIS_fnc_wpSlingLoadAttach function, which says that it takes three parameters: posLimit, failCode, and weight. But the example provided uses six parameters...

[player, dude, 50, 10, {hintC "You lost the cargo!"}, 1000] spawn BIS_fnc_wpSlingLoadAttach;

Why is the example passing more parameters than the function accepts? What are "player", "dude", and "50"?

Just when I think I've figured out the wonky SQF syntax I come across things like the above which make me think I'm missing something.

Share this post


Link to post
Share on other sites

The reason you see the assignment to '0' is because the editor is a bit weird. In many of the editor fields such as, initialization fields, condition field of triggers and other places you cannot have expressions that have a result. Using the command 'execVM' returns a handle - that is, some value. This is not permitted. However, there is no result in an assignment expression so by performing an assignment the result of the expression changes from a script handle to nothing which is allowed. This restriction does not exist outside the editor. 0 is often chosen since then you don't create a variable in the global scope. Some uses 'nul' instead and others something else.

Regarding your second question, maybe the function has undocumented optional variables. You can create functions which take optional values like this:

takesOptional = {
  _required = _this select 0;
  _optional = if (count _this > 1) then {_this select 1} else {"Default value"};
   ......
};

EDIT:

It looks like it is the 3 first parameters that are not documented and the last 3, which is those documented, are optional.

Edited by Muzzleflash

Share this post


Link to post
Share on other sites

If I'm testing in the editor, I do nullRet = [] "SomeScript.sqf";

Makes so much more sense...

I've seen people replacing the Nil value as well, that's a big no no.

Share this post


Link to post
Share on other sites

In triggers and such, I use a local return value like "_go = [] execVM "SomeScript.sqf"" since _go has no meaning outside of this scope. 0 is safe to use as well. In general sqf scripts, you don't need to assign any return value, simply use "[] execVM "SomeScript.sqf"" and you will be fine, unless you want the return handle which I do use on occasion.

Share this post


Link to post
Share on other sites

the returns for scripts and functions have their uses - you can check when a script completes with scriptDone, so long as you know the handle. 0 is but a number, and cannot be assigned a value (unlike nil, which can) so its safe to use it when you dont want to return a handle or value from a script.

Share this post


Link to post
Share on other sites

Thank you all. It makes sense now... ok, it doesn't make "sense"... but at least I understand the purpose of the construct now. And I've found out about another misconception that I had: the expression _i=5 evaluates to "nothing" instead of 5 like I would expect.

EDIT:

It looks like it is the 3 first parameters that are not documented and the last 3, which is those documented, are optional.

Hmmm, I've looked at the code and I don't see where. This is the bit that parses the parameters.

_posLimit = [_params,0,-1,[0,true]] call bis_fnc_param;
_failCode = [_params,1,{},[{}]] call bis_fnc_param;
_weight = [_params,2,-1,[0]] call bis_fnc_param;

I don't see the code access parameters anywhere else, and the above is parsing the first three parameters, which, according to the example in the wiki should be "player", "dude", and "50"...

However, this is a function introduced in TOH (according to the wiki), so maybe I should take this question to the TOH Editing forum (unless any SQF gurus here recognize what is going on here).

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  

×