{"name":"call","title":"call","type":"command","url":"https://community.bistudio.com/wiki/call","revid":373729,"updated":"2025-06-23T13:37:41Z","groups":["Program Flow"],"status":"ok","games":{"ofp":"1.85","ofpe":"1.00","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofp 1.85","arma3_since":"0.50","description":"Adds given set of compiled instructions to the current stack and waits for it to finish and return, provides an option to pass arguments to the executed Code.\nSee Scheduler to learn more about how the code is executed and behaves.","syntaxes":[{"syntax":"call code","params":[{"name":"code","type":"Code","description":"compiled instructions\n\n> [!NOTE]\n> **Operation Flashpoint:** Operation Flashpoint takes String.\n\n> [!NOTE]\n> This way of calling has access to its parent scope's `_this`, as all it does is creating a scope.","type_expr":"Code"}],"returns":{"type":"Anything","type_expr":"Anything","description":"the last value given in the function is returned - see the topic Function for more information"},"form":"unary","right":{"text":"code"}},{"syntax":"args call code","params":[{"name":"args","type":"Anything","description":"arguments that are passed to the function in the `_this` variable.","type_expr":"Anything"},{"name":"code","type":"Code","description":"compiled instructions\n\n> [!NOTE]\n> **Operation Flashpoint:** Operation Flashpoint takes String.","type_expr":"Code"}],"returns":{"type":"Anything","type_expr":"Anything","description":"the last value given in the function is returned. See the topic Function for more information."},"form":"binary","left":{"text":"args"},"right":{"text":"code"}},{"syntax":"hashMapObj call [methodName, arguments]","since":"arma3 2.14","params":[{"name":"hashMapObj","type":"HashMap","description":"the HashMap (not necessarily created through createHashMapObject) to call the method on","type_expr":"HashMap"},{"name":"methodName","type":"String","description":"the name of the method to call (the method must be defined in *hashMapObj*; see createHashMapObject)","type_expr":"String"},{"name":"arguments","type":"Anything","optional":true,"default":"parent scope's `_this`","description":"arguments passed to the method in the `_this` variable","type_expr":"Anything","text":"arguments: Anything - (Optional, default parent scope's `_this`) arguments passed to the method in the `_this` variable"}],"returns":{"type":"Anything","type_expr":"Anything","description":"the value returned by the methodName method","text":"Anything - the value returned by the *methodName* method"},"form":"binary","left":{"text":"hashMapObj"},"right":{"text":"[methodName, arguments]"}}],"examples":[{"code":["call { hint str 123; };"]},{"code":["123 call { hint str _this; };"]},{"code":["_sum = [1, 2] call { (_this select 0) + (_this select 1); };\nhint str _sum; // displays 3"]},{"code":["123 call compile \"hint str _this;\";"]},{"code":["_result = 123 call compile preprocessFileLineNumbers \"myFile.sqf\";"]},{"text":"```sqf\nprivate _hashMapObj = createHashMapObject [[\n    [\"MyMethod\", { systemChat (\"MyMethod arguments: \" + str _this); }]\n]];\n\n_hashMapObj call [\"MyMethod\", [\"Hello there\", player, 123]]; // hints 'MyMethod arguments: [\"Hello there\", player, 123]'\n```","code":["private _hashMapObj = createHashMapObject [[\n\t[\"MyMethod\", { systemChat (\"MyMethod arguments: \" + str _this); }]\n]];\n\n_hashMapObj call [\"MyMethod\", [\"Hello there\", player, 123]]; // hints 'MyMethod arguments: [\"Hello there\", player, 123]'"]}],"see_also":["spawn","execVM","canSuspend","compile","compileScript","preprocessFile","remoteExec","remoteExecCall"],"notes":[{"user":"Leopard20","date":"2021-11-05T10:52:49Z","text":"Contrary to a widespread misconception in the community, call doesn't necessarily execute the code in the Unscheduled Environment. Call simply means: \"execute the code here\", just like how you execute a code using then (`if (true) then _code`) or do. Therefore it does not change the environment:\n\n| *call* executed in environment: | Resulting environment of the code: |\n|---|---|\n| Scheduled | Scheduled |\n| Unscheduled | Unscheduled |\n\nThis means that doing something like this (which is misused very often):\n\n```sqf\nprivate _handle = _params spawn MY_fnc_Function;\nwaitUntil { scriptDone _handle };\n```\n\nis not needed, because a lot of performance would be wasted compared to simply doing this:\n\n```sqf\n_params call MY_fnc_Function;\n```\n\nwhich does the exact same thing as the previous code, except no new *\"scheduler thread\"* is created and the function executes seamlessly, plus the added performance benefit as mentioned before.\nIf it is necessary to execute a code in the Unscheduled Environment, one can use isNil instead:\n\n```sqf\nisNil {_params call MY_fnc_Function}; // MY_fnc_Function is always executed unscheduled, regardless of the current environment\n```\n\nor if there are no parameters, one can simply do this:\n\n```sqf\nisNil MY_fnc_Function\n```"}]}