Saving while a scheme runs
What this page is for
Section titled “What this page is for”Your code can ask for a save at any moment, and some of that code runs while a scheme’s node is running. This page says what Intrigues does then, so a load never runs a node twice.
Why a save inside a node waits
Section titled “Why a save inside a node waits”If a save were taken while a node was running, that node would be written as waiting. A load would run it again, and its effect would happen twice. So Intrigues never takes the capture inside the node.
“Inside a node” means any code that runs while a scheme’s flow runs: a node’s Run, a Run Code method, a Signal Receiver, a trigger, a Changed listener, a scheme-end listener, an actor or accomplice listener.
What each call does
Section titled “What each call does”| You call | What happens inside a node |
|---|---|
SaveAsync, SaveCurrentAsync, AutosaveAsync (a slot save of the whole game) |
The save waits until the node has returned, at the end of the frame, and then saves. SaveResult.Deferred is true and the problems hold SaveDeferred, an information line. |
IntrigueSave.State.Capture() |
Refused: CaptureStatus.InsideNode, no data, one warning. |
IntrigueSaveSystem.Capture() |
Refused: it returns null, with one warning. |
Capture with CaptureOptions.InsideNode = InsideNodeCapture.Warn |
Captured anyway, with the warning CaptureInsideNode. A load of that capture runs the node again. |
A slot save does not wait for a partial save (SaveRequest.Parts): a partial save holds no world.
If the node has still not returned after the frames a save waits, the save is refused with SaveStatus.InsideNode, the code CaptureInsideNode is raised as an error and nothing is written. The code waits at most 600 frames.
This wait does not depend on the Defer Inside Day setting, which only covers a save asked inside a day’s thinking.
Never wait for a save on the main thread
Section titled “Never wait for a save on the main thread”With a storage that answers at once, such as WebGL or a memory storage, a slot save inside a node finishes at the end of the frame, not inside the call. So never block on the save’s task on the main thread: no .Result, no .Wait(). That hangs the game, because the save needs the frame to end.
Await the task from a method of your own. Example, not compiled:
// Ask, then await. Never IntrigueSaveSystem.Instance.SaveAsync("slot1").Result or .Wait().var saved = await IntrigueSaveSystem.Instance.SaveAsync("slot1");if (saved.Deferred) { /* the save waited for a node to return */ }Limits
Section titled “Limits”The product’s notes say only the synchronous part of a Run counts. A custom node that is still awaiting when the save is taken is saved as waiting and runs again on load, also when the save is asked from the part it awaits. A load asked from inside a node is otherwise not covered.
How it connects
Section titled “How it connects”- The calls and their results: Saving and loading, Save and load results.
- To save from a node on purpose, Run Code calls your method.
- Other limits of saving: Limits of saving in 2.0.