API Reference of GS2-StateMachine SDK for Game Engine
Model
EzStatus
Status of state machine
Type | Require | Default | Limitation | Description | |
---|---|---|---|---|---|
statusId | string | ✓ | ~ 1024 chars | Status of State Machine GRN | |
name | string | ✓ | UUID | ~ 36 chars | Status name |
stacks | List<EzStackEntry> | ~ 1024 items | Stack | ||
variables | List<EzVariable> | ~ 1000 items | State variables for each state machine | ||
status | enum [‘Running’, ‘Wait’, ‘Pass’, ‘Error’] | ✓ | “Running” | ~ 128 chars | Status |
lastError | string | ~ 1024 chars | Last error | ||
transitionCount | int | ✓ | 0 | ~ 2147483645 | Number of transitions |
EzStackEntry
Type | Require | Default | Limitation | Description | |
---|---|---|---|---|---|
stateMachineName | string | ✓ | ~ 128 chars | Name of the state machine | |
taskName | string | ✓ | ~ 128 chars | Task name |
EzVariable
Type | Require | Default | Limitation | Description | |
---|---|---|---|---|---|
stateMachineName | string | ✓ | ~ 128 chars | Name of the state machine | |
value | string | ✓ | ~ 1048576 chars | Value |
Methods
emit
Send an event to the state machine
Request
Type | Require | Default | Limitation | Description | |
---|---|---|---|---|---|
namespaceName | string | ✓ | ~ 32 chars | Namespace name | |
accessToken | string | ✓ | ~ 128 chars | User Id | |
statusName | string | ✓ | ~ 36 chars | Status name | |
eventName | string | ✓ | ~ 36 chars | Event name | |
args | string | ✓ | “{}” | ~ 4096 chars | Arguments to be passed to the state machine |
Result
Type | Description | |
---|---|---|
item | EzStatus | Status of State Machine |
Implementation Example
var domain = gs2.StateMachine.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).Status(
statusName: "$status1.name"
);
var result = await domain.EmitAsync(
eventName: "event-0001",
args: "{\"value1\": \"value1\", \"value2\": 2.0, \"value3\": 3}"
);
var item = await result.ModelAsync();
var domain = gs2.StateMachine.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).Status(
statusName: "$status1.name"
);
var future = domain.EmitFuture(
eventName: "event-0001",
args: "{\"value1\": \"value1\", \"value2\": 2.0, \"value3\": 3}"
);
yield return future;
if (future.Error != null)
{
onError.Invoke(future.Error, null);
yield break;
}
var future2 = future.Result.Model();
yield return future2;
if (future2.Error != null)
{
onError.Invoke(future2.Error, null);
yield break;
}
var result = future2.Result;
const auto Domain = Gs2->StateMachine->Namespace(
"namespace-0001" // namespaceName
)->Me(
AccessToken
)->Status(
"$status1.name" // statusName
);
const auto Future = Domain->Emit(
"event-0001",
"{\"value1\": \"value1\", \"value2\": 2.0, \"value3\": 3}" // args
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError())
{
return false;
}
// obtain changed values / result values
const auto Future2 = Future->GetTask().Result()->Model();
Future2->StartSynchronousTask();
if (!TestFalse(WHAT, Future2->GetTask().IsError())) return false;
const auto Result = Future2->GetTask().Result();
exit
Delete the state machine that has finished
Request
Type | Require | Default | Limitation | Description | |
---|---|---|---|---|---|
namespaceName | string | ✓ | ~ 32 chars | Namespace name | |
accessToken | string | ✓ | ~ 128 chars | User Id | |
statusName | string | ✓ | ~ 36 chars | Status name |
Result
Type | Description | |
---|---|---|
item | EzStatus | Exited state machine |
Implementation Example
var domain = gs2.StateMachine.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).Status(
statusName: "$status1.name"
);
var result = await domain.ExitAsync(
);
var domain = gs2.StateMachine.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).Status(
statusName: "$status1.name"
);
var future = domain.ExitFuture(
);
yield return future;
if (future.Error != null)
{
onError.Invoke(future.Error, null);
yield break;
}
const auto Domain = Gs2->StateMachine->Namespace(
"namespace-0001" // namespaceName
)->Me(
AccessToken
)->Status(
"$status1.name" // statusName
);
const auto Future = Domain->Exit(
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError())
{
return false;
}
getStatus
Get the current status of the state machine
Request
Type | Require | Default | Limitation | Description | |
---|---|---|---|---|---|
namespaceName | string | ✓ | ~ 32 chars | Namespace name | |
accessToken | string | ✓ | ~ 128 chars | User Id | |
statusName | string | ✓ | ~ 36 chars | Status name |
Result
Type | Description | |
---|---|---|
item | EzStatus | Status of State Machine |
Implementation Example
var domain = gs2.StateMachine.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).Status(
statusName: "$status1.name"
);
var item = await domain.ModelAsync();
var domain = gs2.StateMachine.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).Status(
statusName: "$status1.name"
);
var future = domain.Model();
yield return future;
var item = future.Result;
const auto Domain = Gs2->StateMachine->Namespace(
"namespace-0001" // namespaceName
)->Me(
AccessToken
)->Status(
"$status1.name" // statusName
);
const auto Future = Domain.Model();
Future->StartSynchronousTask();
if (Future->GetTask().IsError())
{
return false;
}
Value change event handling
var domain = gs2.StateMachine.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).Status(
statusName: "$status1.name"
);
// Start event handling
var callbackId = domain.Subscribe(
value => {
// Called when the value changes
// The "value" is passed the value after the change.
}
);
// Stop event handling
domain.Unsubscribe(callbackId);
var domain = gs2.StateMachine.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).Status(
statusName: "$status1.name"
);
var future = domain.Model();
yield return future;
var item = future.Result;
const auto Domain = Gs2->StateMachine->Namespace(
"namespace-0001" // namespaceName
)->Me(
AccessToken
)->Status(
"$status1.name" // statusName
);
// Start event handling
const auto CallbackId = Domain->Subscribe(
[](TSharedPtr<Gs2::StateMachine::Model::FStatus> value) {
// Called when the value changes
// The "value" is passed the value after the change.
}
);
// Stop event handling
Domain->Unsubscribe(CallbackId);
Warning
This event is called when the value in the local cache that the SDK has is changed.
The local cache will only be changed by executing the SDK’s API, or by executing a stamp sheet via GS2-Distributor with GS2-Gateway notification enabled, or by executing a GS2-JobQueue with GS2-Gateway notification enabled. GS2-Gateway notification enabled.
Therefore, callbacks will not be invoked if the value is changed in any other way.
listStatuses
Get the current status of the state machine
Request
Type | Require | Default | Limitation | Description | |
---|---|---|---|---|---|
namespaceName | string | ✓ | ~ 32 chars | Namespace name | |
accessToken | string | ✓ | ~ 128 chars | User Id | |
status | enum [‘Running’, ‘Wait’, ‘Pass’, ‘Error’] | ~ 128 chars | Status | ||
pageToken | string | ~ 1024 chars | Token specifying the position from which to start acquiring data | ||
limit | int | ✓ | 30 | 1 ~ 1000 | Number of data acquired |
Result
Type | Description | |
---|---|---|
items | List<EzStatus> | List of Status of State Machine |
nextPageToken | string | Page token to retrieve the rest of the listing |
Implementation Example
var domain = gs2.StateMachine.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
);
var items = await domain.StatusesAsync(
).ToListAsync();
var domain = gs2.StateMachine.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
);
var it = domain.Statuses(
);
List<EzStatus> items = new List<EzStatus>();
while (it.HasNext())
{
yield return it.Next();
if (it.Error != null)
{
onError.Invoke(it.Error, null);
break;
}
if (it.Current != null)
{
items.Add(it.Current);
}
else
{
break;
}
}
const auto Domain = Gs2->StateMachine->Namespace(
"namespace-0001" // namespaceName
)->Me(
AccessToken
);
const auto It = Domain->Statuses( // status
);
for (auto Item : *It)
{
}
Value change event handling
var domain = gs2.StateMachine.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
);
// Start event handling
var callbackId = domain.SubscribeStatuses(
() => {
// Called when an element of the list changes.
}
);
// Stop event handling
domain.UnsubscribeStatuses(callbackId);
var domain = gs2.StateMachine.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
);
var it = domain.Statuses(
);
List<EzStatus> items = new List<EzStatus>();
while (it.HasNext())
{
yield return it.Next();
if (it.Error != null)
{
onError.Invoke(it.Error, null);
break;
}
if (it.Current != null)
{
items.Add(it.Current);
}
else
{
break;
}
}
const auto Domain = Gs2->StateMachine->Namespace(
"namespace-0001" // namespaceName
)->Me(
AccessToken
);
// Start event handling
const auto CallbackId = Domain->SubscribeStatuses(
[]() {
// Called when an element of the list changes.
}
);
// Stop event handling
Domain->UnsubscribeStatuses(CallbackId);
Warning
This event is called when the value in the local cache that the SDK has is changed.
The local cache will only be changed by executing the SDK’s API, or by executing a stamp sheet via GS2-Distributor with GS2-Gateway notification enabled, or by executing a GS2-JobQueue with GS2-Gateway notification enabled. GS2-Gateway notification enabled.
Therefore, callbacks will not be invoked if the value is changed in any other way.