> For the complete documentation index, see [llms.txt](/llms.txt)

# GS2-StateMachine Script Trigger Reference

Reference for event triggers that call extended scripts



## Trigger

### start

Start state machine

**Related methods:**
startStateMachineByUserId - Start state machine by User ID


#### Synchronous Execution Script

The script is executed synchronously before the start state machine process.

##### Request

| | Type | Description |
| --- | --- | --- |
| namespace | [Namespace](../sdk/#namespace) | Namespace |
| stateMachineMaster | [StateMachineMaster](../sdk/#statemachinemaster) | State machine master data |
| status | [Status](../sdk/#status) | Status |
| userId | string | User ID |
| parameters | string | Arguments to be passed to the state machine |

##### Result

|  | Type | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- |
| permit | bool | ✓ |  |  | Whether to allow start |

##### Implementation Example


**Lua**
```lua

-- Request
local namespace = args.namespace
local stateMachineMaster = args.stateMachineMaster
local status = args.status
local userId = args.userId
local parameters = args.parameters

-- Business logic:
local permit = true

-- Result
result = {
  permit=permit
}
```


#### Asynchronous Execution Script

The script is executed asynchronously after the start state machine process.

##### Request

| | Type | Description |
| --- | --- | --- |
| namespace | [Namespace](../sdk/#namespace) | Namespace |
| stateMachineMaster | [StateMachineMaster](../sdk/#statemachinemaster) | State machine master data |
| status | [Status](../sdk/#status) | Status |
| userId | string | User ID |
| parameters | string | Arguments to be passed to the state machine |


##### Implementation Example


**Lua**
```lua

-- Request
local namespace = args.namespace
local stateMachineMaster = args.stateMachineMaster
local status = args.status
local userId = args.userId
local parameters = args.parameters

-- Asynchronous scripts typically do not affect the API response.
-- These scripts are typically used for logging, analytics, external notifications, and similar purposes.

result = {
}
```


---
  
### pass

Pass state machine

**Related methods:**
emit - Send an event to the state machine
emitByUserId - Send an event to the state machine by User ID
report - Report multiple events to the state machine
reportByUserId - Report multiple events to the state machine by User ID


#### Synchronous Execution Script

The script is executed synchronously before the pass state machine process.

##### Request

| | Type | Description |
| --- | --- | --- |
| namespace | [Namespace](../sdk/#namespace) | Namespace |
| stateMachineMaster | [StateMachineMaster](../sdk/#statemachinemaster) | State machine master data |
| status | [Status](../sdk/#status) | Status |
| userId | string | User ID |

##### Result

|  | Type | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- |
| permit | bool | ✓ |  |  | Whether to allow the state machine to finish normally |

##### Implementation Example


**Lua**
```lua

-- Request
local namespace = args.namespace
local stateMachineMaster = args.stateMachineMaster
local status = args.status
local userId = args.userId

-- Business logic:
local permit = true

-- Result
result = {
  permit=permit
}
```


#### Asynchronous Execution Script

The script is executed asynchronously after the pass state machine process.

##### Request

| | Type | Description |
| --- | --- | --- |
| namespace | [Namespace](../sdk/#namespace) | Namespace |
| stateMachineMaster | [StateMachineMaster](../sdk/#statemachinemaster) | State machine master data |
| status | [Status](../sdk/#status) | Status |
| userId | string | User ID |


##### Implementation Example


**Lua**
```lua

-- Request
local namespace = args.namespace
local stateMachineMaster = args.stateMachineMaster
local status = args.status
local userId = args.userId

-- Asynchronous scripts typically do not affect the API response.
-- These scripts are typically used for logging, analytics, external notifications, and similar purposes.

result = {
}
```


---
  
### error

Error state machine

**Related methods:**
emit - Send an event to the state machine
emitByUserId - Send an event to the state machine by User ID
report - Report multiple events to the state machine
reportByUserId - Report multiple events to the state machine by User ID


#### Synchronous Execution Script

The script is executed synchronously before the error state machine process.

##### Request

| | Type | Description |
| --- | --- | --- |
| namespace | [Namespace](../sdk/#namespace) | Namespace |
| stateMachineMaster | [StateMachineMaster](../sdk/#statemachinemaster) | State machine master data |
| status | [Status](../sdk/#status) | Status |
| userId | string | User ID |

##### Result

|  | Type | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- |
| permit | bool | ✓ |  |  | Whether to allow an error state machine termination |

##### Implementation Example


**Lua**
```lua

-- Request
local namespace = args.namespace
local stateMachineMaster = args.stateMachineMaster
local status = args.status
local userId = args.userId

-- Business logic:
local permit = true

-- Result
result = {
  permit=permit
}
```


#### Asynchronous Execution Script

The script is executed asynchronously after the error state machine process.

##### Request

| | Type | Description |
| --- | --- | --- |
| namespace | [Namespace](../sdk/#namespace) | Namespace |
| stateMachineMaster | [StateMachineMaster](../sdk/#statemachinemaster) | State machine master data |
| status | [Status](../sdk/#status) | Status |
| userId | string | User ID |


##### Implementation Example


**Lua**
```lua

-- Request
local namespace = args.namespace
local stateMachineMaster = args.stateMachineMaster
local status = args.status
local userId = args.userId

-- Asynchronous scripts typically do not affect the API response.
-- These scripts are typically used for logging, analytics, external notifications, and similar purposes.

result = {
}
```


---
  



