Save Operation
The main class that handles saving and loading operations.
Many methods related to saving and loading return a SaveOperation<T>
object. The T
represents the result type of the operation.
Working with an Operation
The main purpose of the SaveOperation
class is to support multithreading. Additionally, it allows you to register events, enabling you to receive results or trigger actions precisely when needed.
Getting the Result
You can get the result of an operation by accessing the Result field.
The result is only equal to something after successful completion. See Recommendation.
States
You can get the current State
of the operation with the state
field.
NotStarted
The operation has not begun.
Ongoing
The operation has begun and it has not yet completed.
Completed
The operation has successfully completed.
Canceled
User canceled the operation. An operation can be canceled with saveOperation.Cancel()
.
Failed
The operation failed. This may happen if an error occurred during the operation.
Events
The recommended way of working with operations is by utilizing the available events.
onEnded
A callback for when the operation has completed, canceled, or failed. Events are cleared after the operation has ended.
onCompleted
A callback for when the operation has completed. Events are cleared after the operation has ended.
onFailed
A callback for when the operation has failed. Events are cleared after the operation has ended.
You may use the OnEnd
, OnComplete
, or OnFail
methods respectively to register events.
Recommendation
Below is the recommended scripting pattern to make something happen after the operation has completed while also getting the result. This pattern is recommended because it works no matter what the multithread mode is set to.
NOTE: the SaveOperation
result type may vary. However, it's usually SaveState
or bool
.
The code is simply logging the result in the console after the operation is successfully completed. You can even chain register events as shown below.
Event registration like this is not necessary if the multithread mode is set to disabled.
Example
The code below loads a save state right after ESave is initialized, and then immediately retrieves data from the save state.
It's possible to do the same thing in another way, but only if multithread mode is set to disabled.
Last updated