Results 1 to 6 of 6

Thread: Wresting with SQF syntax

  1. #1

    Wresting with SQF syntax

    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:
    Code:
    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...
    Code:
    [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.

  2. #2
    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:
    Code:
    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.
    Last edited by Muzzleflash; Jan 1 2012 at 21:45.

  3. #3
    Second Lieutenant GossamerSolid's Avatar
    Join Date
    Feb 3 2006
    Location
    Ontario, Canada
    Posts
    4,013
    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.

    Missions/Gamemodes - F.U.B.A.R. (WIP)
    Mods/Addons - Green Sea Conflict (WIP)
    Resources - ArmA 3 Notepad++ Syntax Highlighting

  4. #4
    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.

  5. #5
    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.

  6. #6
    Corporal
    Join Date
    Jul 17 2009
    Location
    New York
    Posts
    66
    Author of the Thread
    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.

    Quote Originally Posted by Muzzleflash View Post
    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.
    Code:
    _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).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •