10. Position and save
10.1 Static facade
| Member | Description |
|---|---|
Dialogue.Position | current DialoguePosition (or null) |
Dialogue.SavePosition() | string ready to be saved |
Dialogue.RestorePosition(snapshot) | rebuilds a DialoguePosition from a string |
Dialogue.SetFunctionProgress(string) | progress of a long function (e.g. "3/7") |
Dialogue.OnPositionChanged | event Action<DialoguePosition> |
Syntax
Dialogue.Position
Dialogue.SavePosition()
Dialogue.RestorePosition(snapshot)
Dialogue.SetFunctionProgress(string)
Dialogue.OnPositionChanged
Parameters
| Parameter | Description |
|---|---|
snapshot | position state string |
| progress value | progress of a long function, for example "3/7" |
Return value
Dialogue.SavePosition() returns a string ready to be saved; Dialogue.RestorePosition(snapshot) returns a DialoguePosition rebuilt from the string.
Notes
Dialogue.Position exposes the current DialoguePosition or null. Dialogue.OnPositionChanged is an event of type Action<DialoguePosition>.
Example
Dialogue.OnPositionChanged += pos =>
{
Debug.Log($"{pos.GraphId} / {pos.NodeId} / line {pos.LineIndex} of {pos.LineCount}");
if (pos.IsInsideFunction)
Debug.Log($"inside function {pos.FunctionActionId}: {pos.FunctionProgress}");
};
string snapshot = Dialogue.SavePosition(); // e.g. PlayerPrefs.SetString("dlg", snapshot)
DialoguePosition pos = Dialogue.RestorePosition(snapshot);
Debug.Log($"restorable at {pos.GraphId}:{pos.NodeId}");
10.2 Fields of DialoguePosition
| Field | Meaning | ||
|---|---|---|---|
GraphId | current graph | ||
NodeId, NodeType | current node | ||
Speaker, Did, LineIndex, LineCount | current line and position in the line | ||
WaitingForChoice, WaitingForAction | waits | ||
FunctionActionId, FunctionProgress | function in progress and its progress | ||
Language, Running | language and dialogue state | ||
IsInsideFunction | shortcut: `WaitingForAction | FunctionActionId != null` |
10.3 Restore model
The engine does not write to disk: the position is captured by the engine and saved by the application code. Restore is designed to be driven by the game: the variables, the quests and the scene are brought back to the desired state and the dialogue restarts from the saved node, maintaining full control over saves, checkpoints and reopening of the scenes.
11. Diagnostics
11.1 Logging
| Member | Description |
|---|---|
DialogueLogger.Enabled | switches the logs on/off |
DialogueLogger.Prefix | [MySys22.DialogueEngine] |
DialogueLogger.Log(...) / LogWarning(...) / LogError(...) | coherent logs |
DialogueLogger.LogError(code, description, detail = null) | log with code [3xx] |
bridge.Validate() | Report with Errors, Warnings, Infos, NodesChecked, LinesChecked, ToText() |
Syntax
DialogueLogger.Enabled
DialogueLogger.Prefix
DialogueLogger.Log(...)
DialogueLogger.LogWarning(...)
DialogueLogger.LogError(...)
DialogueLogger.LogError(code, description, detail = null)
bridge.Validate()
Parameters
| Parameter | Description |
|---|---|
code | numeric code of the message, in the format [3xx] |
description | description of the message |
detail | additional detail; the default value is null |
Notes
DialogueLogger.Prefix corresponds to [MySys22.DialogueEngine]. bridge.Validate() returns a Report with the Errors, Warnings, Infos collections, the NodesChecked, LinesChecked counters and the ToText() method.
11.2 Message filter
The prefix of the messages is MySys22; on device the corresponding filter is adb logcat -s Unity | grep MySys22.