{"name":"execFSM","title":"execFSM","type":"command","url":"https://community.bistudio.com/wiki/execFSM","revid":363581,"updated":"2024-04-07T14:49:31Z","groups":["Program Flow"],"status":"ok","games":{"arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"arma2 1.00","arma3_since":"0.50","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.\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","params":[{"name":"arguments","type":"Anything","description":"arguments accessible as `_this` in the FSM","type_expr":"Anything"},{"name":"fsmFilePath","type":"String","description":"file with FSM code","type_expr":"String"}],"returns":{"type":"Number","type_expr":"Number","description":"FSM handle (also available as `_thisFSM` in the FSM)"},"form":"binary","left":{"text":"arguments"},"right":{"text":"fsmFilePath"}},{"syntax":"execFSM fsmFilePath","params":[{"name":"fsmFilePath","type":"String","description":"file with FSM code","type_expr":"String"}],"returns":{"type":"Number","type_expr":"Number","description":"FSM handle (also available as `_thisFSM` in the FSM)"},"form":"unary","right":{"text":"fsmFilePath"}},{"syntax":"arguments execFSM [fsmFilePath, allowTermination]","since":"arma3 2.18","params":[{"name":"arguments","type":"Anything","description":"arguments accessible as `_this` in the FSM","type_expr":"Anything"},{"name":"fsmFilePath","type":"String","description":"file with FSM code","type_expr":"String"},{"name":"allowTermination","type":"Boolean","description":"true to allow FSM termination with terminate command. Optional, default false","type_expr":"Boolean"}],"returns":{"type":"Number","type_expr":"Number","description":"FSM handle (also available as `_thisFSM` in the FSM)"},"form":"binary","left":{"text":"arguments"},"right":{"text":"[fsmFilePath, allowTermination]"}},{"syntax":"execFSM [fsmFilePath, allowTermination]","since":"arma3 2.18","params":[{"name":"fsmFilePath","type":"String","description":"file with FSM code","type_expr":"String"},{"name":"allowTermination","type":"Boolean","description":"true to allow FSM termination with terminate command. Optional, default false","type_expr":"Boolean"}],"returns":{"type":"Number","type_expr":"Number","description":"FSM handle (also available as `_thisFSM` in the FSM)"},"form":"unary","right":{"text":"[fsmFilePath, allowTermination]"}}],"examples":[{"code":["_id = player execFSM \"test.fsm\";"]},{"code":["_handle = [_a, _b, _c] execFSM \"test.fsm\";"]},{"code":["_handle = execFSM \"test.fsm\";"]}],"see_also":["FSM","FSM Editor Manual","execVM","call","spawn","exec","commandFSM","completedFSM","doFSM","getFSMVariable","setFSMVariable"]}