{"name":"execFSM","operator":null,"title":"execFSM","type":"command","url":"https://community.bistudio.com/wiki/execFSM","revid":363581,"updated":"2024-04-07T14:49:31Z","groups":["Program Flow"],"status":"ok","replaced_by":[],"games":[{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"arma2","name":"Arma 2","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Execute scripted FSM and return the FSM handle or 0 when failed. The FSM file is first searched in the mission folder, then in the campaign scripts folder and finally in the global scripts folder. Argument (if any) are available in `_this` variable inside FSM. Variables set inside FSMs can be read/modified externally, using setFSMVariable and getFSMVariable commands.\n\nThe return value is the FSM handle; it can be used to determine (via completedFSM) when the FSM has finished.\n\n> [!NOTE]\n> **Arma 3:** In Arma 3, the FSM handle is also available within the FSM through the `_thisFSM` variable.\n\nScripted FSMs are added into the scheduler just like exec scripts, execVM scripts and spawn scripts.\n\nTo see what FSMs are currently in the scheduler, use diag_activeMissionFSMs command.\n\n> [!IMPORTANT]\n> While the code placed into any of the sections of FSM cannot be suspended (canSuspend is false), the FSM itself is suspended every simulation between the state's `init` and `precondition` (exception is the **init state**). This is the only place where scripted FSM is suspended/resumed.\n> The usual difference between the state's `init` and `precondition` is 1 frame but if the scheduler is busy it can take longer. See FSM for more information about FSM's structure.","syntaxes":[{"syntax":"arguments execFSM fsmFilePath","since":null,"effect":null,"exec":null,"params":[{"name":"arguments","type":"Anything","optional":false,"default":null,"description":"arguments accessible as `_this` in the FSM","types":["Anything"],"since":null,"text":"arguments: Anything - arguments accessible as `_this` in the FSM"},{"name":"fsmFilePath","type":"String","optional":false,"default":null,"description":"file with FSM code","types":["String"],"since":null,"text":"fsmFilePath: String - file with FSM code"}],"returns":{"type":"Number","types":["Number"],"description":"FSM handle (also available as `_thisFSM` in the FSM)","text":"Number - FSM handle (also available as `_thisFSM` in the FSM)"},"form":"binary","operator":null,"left":{"text":"arguments","types":["Anything"]},"right":{"text":"fsmFilePath","types":["String"]}},{"syntax":"execFSM fsmFilePath","since":null,"effect":null,"exec":null,"params":[{"name":"fsmFilePath","type":"String","optional":false,"default":null,"description":"file with FSM code","types":["String"],"since":null,"text":"fsmFilePath: String - file with FSM code"}],"returns":{"type":"Number","types":["Number"],"description":"FSM handle (also available as `_thisFSM` in the FSM)","text":"Number - FSM handle (also available as `_thisFSM` in the FSM)"},"form":"unary","operator":null,"left":null,"right":{"text":"fsmFilePath","types":["String"]}},{"syntax":"arguments execFSM [fsmFilePath, allowTermination]","since":"arma3 2.18","effect":null,"exec":null,"params":[{"name":"arguments","type":"Anything","optional":false,"default":null,"description":"arguments accessible as `_this` in the FSM","types":["Anything"],"since":null,"text":"arguments: Anything - arguments accessible as `_this` in the FSM"},{"name":"fsmFilePath","type":"String","optional":false,"default":null,"description":"file with FSM code","types":["String"],"since":null,"text":"fsmFilePath: String - file with FSM code"},{"name":"allowTermination","type":"Boolean","optional":false,"default":null,"description":"true to allow FSM termination with terminate command. Optional, default false","types":["Boolean"],"since":null,"text":"allowTermination: Boolean - true to allow FSM termination with terminate command. Optional, default false"}],"returns":{"type":"Number","types":["Number"],"description":"FSM handle (also available as `_thisFSM` in the FSM)","text":"Number - FSM handle (also available as `_thisFSM` in the FSM)"},"form":"binary","operator":null,"left":{"text":"arguments","types":["Anything"]},"right":{"text":"[fsmFilePath, allowTermination]","types":["Array"]}},{"syntax":"execFSM [fsmFilePath, allowTermination]","since":"arma3 2.18","effect":null,"exec":null,"params":[{"name":"fsmFilePath","type":"String","optional":false,"default":null,"description":"file with FSM code","types":["String"],"since":null,"text":"fsmFilePath: String - file with FSM code"},{"name":"allowTermination","type":"Boolean","optional":false,"default":null,"description":"true to allow FSM termination with terminate command. Optional, default false","types":["Boolean"],"since":null,"text":"allowTermination: Boolean - true to allow FSM termination with terminate command. Optional, default false"}],"returns":{"type":"Number","types":["Number"],"description":"FSM handle (also available as `_thisFSM` in the FSM)","text":"Number - FSM handle (also available as `_thisFSM` in the FSM)"},"form":"unary","operator":null,"left":null,"right":{"text":"[fsmFilePath, allowTermination]","types":["Array"]}}],"examples":[{"text":"```sqf\n_id = player execFSM \"test.fsm\";\n```","code":["_id = player execFSM \"test.fsm\";"]},{"text":"```sqf\n_handle = [_a, _b, _c] execFSM \"test.fsm\";\n```","code":["_handle = [_a, _b, _c] execFSM \"test.fsm\";"]},{"text":"```sqf\n_handle = execFSM \"test.fsm\";\n```","code":["_handle = execFSM \"test.fsm\";"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["FSM","FSM Editor Manual","execVM","call","spawn","exec","commandFSM","completedFSM","doFSM","getFSMVariable","setFSMVariable"],"notes":[],"categories":["Arma 2: New Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Program Flow","Introduced with Arma 2 version 1.00","Scripting Commands","Take On Helicopters: Scripting Commands"]}