Class
ChangeHistoryService
NotCreatableService
Must be used by plugins to communicate to Studio how to undo and redo the changes which they make to the experience.
Plugin developers must use ChangeHistoryService to tell Studio how
to undo and redo changes that their plugins make to experiences by recording.
Before making changes, a plugin calls
ChangeHistoryService:TryBeginRecording(), remembering the identifier
it assigns, then after making changes, the Plugin calls
ChangeHistoryService:FinishRecording() to complete the recording.
Plugins may also programmatically invoke an undo or redo through
ChangeHistoryService:Undo() or ChangeHistoryService:Redo().
ChangeHistoryService is not enabled at runtime, so calling its methods
in a running experience has no effect.
Methods 10#
| FinishRecording | Communicates to Studio that the identified recording is finished and to take the final operation to complete the recording.PluginSecurity security |
| GetCanRedo | Returns whether there is an action available to redo and, if so, the name of that action.PluginSecurity security |
| GetCanUndo | Returns whether there is an action available to undo and, if so, the name of that action.PluginSecurity security |
| IsRecordingInProgress | Returns whether the plugin currently has a recording in progress, optionally checking for a specific recording identifier.PluginSecurity security |
| Redo | Re-executes the most recently undone action, advancing forward through the undo/redo history.PluginSecurity security |
| ResetWaypoints | Clears the undo/redo history by collapsing it into a single base waypoint.PluginSecurity security |
| SetEnabled | Sets whether or not the ChangeHistoryService is enabled.PluginSecurity security |
| SetWaypoint | Sets a new waypoint which can be used as an undo or redo point.PluginSecurity security |
| TryBeginRecording | Begins tracking changes made to the data model into a recording.PluginSecurity security |
| Undo | Reverts the most recent action, stepping backward through the undo/redo history.PluginSecurity security |
FinishRecording(identifier: string, operation: FinishRecordingOperation, finalOptions: Dictionary?): ()#
PluginSecurity security
Completes a recording that was started with
TryBeginRecording(). Pass
the identifier returned by that call along with an
FinishRecordingOperation describing what to do with the recorded
changes:
FinishRecordingOperation.Commitadds the changes to the undo/redo history as a new waypoint.FinishRecordingOperation.Canceldiscards the recording and reverts the changes it captured. Theidentifieris ignored for this operation, so a plugin can cancel its own in-progress recording without knowing the identifier.FinishRecordingOperation.Appendmerges the recording into the waypoint that immediately precedes it rather than creating a new one.
When the recording finishes, this method fires
OnRecordingFinished,
forwarding the finalOptions table. It raises an error if the calling
plugin has no recording in progress, or if operation is not
FinishRecordingOperation.Cancel and identifier does not match the
active recording. It has no effect when the service is disabled or while
an undo or redo is in progress.
| Name | Type | Default | Description |
|---|---|---|---|
identifier | string | Identifies the recording from the previous call to
TryBeginRecording().
If the operation is FinishRecordingOperation.Cancel, this value
is ignored, and the recording is determined by context. | |
operation | FinishRecordingOperation | Specifies the operation to take. | |
finalOptions | Dictionary? | Optional table of values to pass to
OnFinishRecording. |
Returns
()
GetCanRedo(): Tuple#
PluginSecurity security
Reports whether Redo() currently has
an action available to replay. It returns a boolean that is true when a
redoable waypoint exists ahead of the current position in the undo/redo
history; when that boolean is true, it also returns the name of the
waypoint that the next redo would replay.
The boolean is false, with no name returned, when the redo stack is
empty because the newest waypoint is already the current one, or when the
service is disabled (which is always the case at runtime).
Returns
Tuple—truefollowed by the name of the action that would be redone when a redo is available; otherwisefalse.
GetCanUndo(): Tuple#
PluginSecurity security
Reports whether Undo() currently has
an action available to revert. It returns a boolean that is true when an
undoable waypoint exists at the current position in the undo/redo history;
when that boolean is true, it also returns the name of the waypoint that
the next undo would revert.
The boolean is false, with no name returned, when the undo stack is
empty because the position is already at the base waypoint, or when the
service is disabled (which is always the case at runtime).
Returns
Tuple—truefollowed by the name of the action that would be undone when an undo is available; otherwisefalse.
IsRecordingInProgress(identifier: string?): boolean#
PluginSecurity security
Reports whether the calling plugin has a recording in progress that was
started with
TryBeginRecording().
When called without an identifier, it returns true if any recording is
active for the plugin. When an identifier is supplied, it returns true
only if the active recording's identifier matches that value. It returns
false when the service is disabled or when the plugin has no active
recording.
| Name | Type | Default | Description |
|---|---|---|---|
identifier | string? | Optional identifier of a specific recording to check for. When omitted, the method reports whether any recording is in progress for the plugin. |
Returns
boolean—trueif a matching recording is in progress; otherwisefalse.
Redo(): ()#
PluginSecurity security
Replays the waypoint immediately ahead of the current position in the
undo/redo history, redoing the action that a matching
Undo() had reverted, and advances the
redo pointer forward by one waypoint. After the waypoint is replayed, it
fires OnRedo with the name of the
redone waypoint.
This method raises an error if a play is already in progress, if the
service is disabled (which is always the case at runtime), or if there is
nothing left to redo. Call
GetCanRedo() first to confirm a
redo is available.
Returns
()
ResetWaypoints(): ()#
PluginSecurity security
Records the current state as a waypoint named base and then merges every
existing waypoint into that single waypoint, leaving no actions to undo or
redo. Use this to establish a clean starting point so that later
Undo() calls cannot revert past the
current state.
This method has no effect when the service is disabled (which is always the case at runtime).
Returns
()
SetEnabled(state: boolean): ()#
PluginSecurity security
Sets whether or not the ChangeHistoryService is enabled. When set to false, the undo/redo list is cleared, and does not repopulate. When set to true again, the original list is not restored, but further operations append to the list once more
| Name | Type | Default | Description |
|---|---|---|---|
state | boolean | Whether to enable (true) or disable (false) the service. |
Returns
()
SetWaypoint(name: string): ()#
PluginSecurity security
This method will be deprecated soon in favor of
TryBeginRecording().
ChangeHistoryService tracks plugin history as a stream of property
changes. SetWaypoint() creates
a cut in that stream of property changes so that the undo and redo actions
know where to stop.
By convention, user-invoked actions in Studio must call
SetWaypoint() after
completing their set of changes to the experience. Calling it before a
set of changes may clean up another misbehaving plugin which failed to set
a waypoint, but it's a poor reason to justify such usage in your own
plugin.
| Name | Type | Default | Description |
|---|---|---|---|
name | string | The name to assign to the new waypoint, which appears in the undo/redo history. |
Returns
()
TryBeginRecording(name: string, displayName: string?): string?#
PluginSecurity security
This method begins a recording to track changes to the data model. You must call it prior to making changes to avoid future warnings or errors.
When the recording is completed, you call
FinishRecording() with the
returned recording identifier to complete the recording and update the
undo/redo stack.
This method will return nil if it fails to begin a recording. Recordings
fail if the plugin already has a recording in progress, or if the user is
in a solo playtest.
You may use
IsRecordingInProgress()
to check the recording status of the plugin.
| Name | Type | Default | Description |
|---|---|---|---|
name | string | Name of the action being performed suitable for logging and coding purposes. | |
displayName | string? | Name of the action being performed to display to the user. |
Returns
string?— A unique string identifier for the recording on success, ornilif the recording could not be started.
Undo(): ()#
PluginSecurity security
Unplays the waypoint at the current position in the undo/redo history,
reverting the most recent recorded action, and steps the undo pointer back
by one waypoint. After the waypoint is reverted, it fires
OnUndo with the name of the undone
waypoint.
This method raises an error if a play is already in progress, if the
service is disabled (which is always the case at runtime), or if there is
nothing left to undo. Call
GetCanUndo() first to confirm an
undo is available.
Returns
()
Events 4#
| OnRecordingFinished | Fired when the user completes an action. Parameters come from
TryBeginRecording() and
FinishRecording().PluginSecurity security |
| OnRecordingStarted | Fired when the user begins an action. Parameters come from
TryBeginRecording().PluginSecurity security |
| OnRedo | Fires after an action is redone, reporting the name of the action that was replayed.PluginSecurity security |
| OnUndo | Fires after an action is undone, reporting the name of the action that was reverted.PluginSecurity security |
OnRecordingFinished(name: string, displayName: string?, identifier: string?, operation: FinishRecordingOperation, finalOptions: Dictionary?)#
PluginSecurity security
Fires when a recording started with
TryBeginRecording() is
completed through
FinishRecording(). The
operation argument reports how the recording was finished (Commit,
Cancel, or Append), and finalOptions is the optional table that was
passed to FinishRecording().
| Name | Type | Default | Description |
|---|---|---|---|
name | string | Name of the action being performed suitable for logging and coding purposes. | |
displayName | string? | Name of the action being performed to display to the user. | |
identifier | string? | The identifier for the recording. | |
operation | FinishRecordingOperation | The FinishRecordingOperation that completed the recording,
either Commit, Cancel, or Append. | |
finalOptions | Dictionary? | Optional table from
FinishOperation(). |
OnRecordingStarted(name: string, displayName: string?)#
PluginSecurity security
Fires when a plugin begins a recording with
TryBeginRecording(),
carrying the same name and displayName values that were passed to that
call.
| Name | Type | Default | Description |
|---|---|---|---|
name | string | Name of the action being performed suitable for logging and coding purposes. | |
displayName | string? | Name of the action being performed to display to the user. |
OnRedo(waypoint: string)#
PluginSecurity security
Fires immediately after Redo() replays
a waypoint, whether the redo was triggered by the user through Studio or
invoked programmatically. The waypoint argument is the name of the
action that was redone, matching the name that was recorded for that
waypoint.
| Name | Type | Default | Description |
|---|---|---|---|
waypoint | string | The name of the waypoint (action) that was redone. |
OnUndo(waypoint: string)#
PluginSecurity security
Fires immediately after Undo() reverts
a waypoint, whether the undo was triggered by the user through Studio or
invoked programmatically. The waypoint argument is the name of the
action that was undone, matching the name that was recorded for that
waypoint.
| Name | Type | Default | Description |
|---|---|---|---|
waypoint | string | The name of the waypoint (action) that was undone. |
Inherited members#
Inherited from Instance 58
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild