Keep
Keep class holds the data for a specific key in a store, and methods to manipulate data.
Types
Session
type
Session =
{
PlaceId:
number
,
JobId:
string
}
MetaData
type
MetaData =
{
LastUpdate:
number
,
Created:
number
,
LoadCount:
number
}
Properties
GlobalStateProcessor
Define how to process global updates, by default just locks the global update (this is only ran if the Keep is online).
The function reveals the lock and remove global update function through the parameters.
WARNING
Updates must be locked eventually in order for .OnGlobalUpdate to get fired.
DANGER
The lock and remove function revealed here are NOT the same as the ones in the Keep class, they are only for this function.
OnGlobalUpdate
Fired when a new global update is locked and ready to be processed, which can happen only during save.
WARNING
ONLY locked globals are fired.
Releasing
Keep.Releasing:
Signal
<
Promise
<
(
)
>
>
Fired when the Keep is releasing (fires before internally released, but during session release).
keep.Releasing:Connect(function(state)
print(`Releasing {keep:Identify()}`)
state:andThen(function()
print(`Released {keep:Identify()}`)
end, function()
print(`Failed to release {keep:Identify()}`)
end)
end)
Saving
Keep.Saving:
Signal
<
Promise
<
(
)
>
>
Fired when the Keep is saving, resolves on complete.
keep.Saving:Connect(function(state)
print(`Saving {keep:Identify()}`)
state:andThen(function()
print(`Saved {keep:Identify()}`)
end):catch(function()
print(`Failed to save {keep:Identify()}`)
end)
end)
Overwritten
Keep.Overwritten:
Signal
<
boolean
>
Fired when the Keep has been overwritten. Keep will be released if isReleasingSession
is set to true
.
keep.Overwritten:Connect(function(isReleasingSession)
print(`{keep:Identify()} has been overwritten. Is releasing session: {isReleasingSession}`)
end)
Functions
Save
Keep:
Save
(
) →
Promise
<
(
)
>
Performs a manual save.
WARNING
Calling :Save()
manually will reset the auto save timer on the Keep.
DANGER
Using :Save()
on a view-only Keep will error. Use :Overwrite() instead.
Release
Keep:
Release
(
) →
Promise
<
(
)
>
Releases the session lock to allow other servers to access the Keep.
DANGER
This is called before internal release, but after session release, no edits can be made after this point.
Overwrite
Keep:
Overwrite
(
shouldKeepExistingSession:
boolean?
) →
Promise
<
(
)
>
Used to overwrite a view-only Keep.
shouldKeepExistingSession
controls the behavior of the server with the active session lock, defaults to false
.
Destroy
Keep:
Destroy
(
) →
(
)
Destroys the Keep, removing all signals connections. Should be used only for cleaning view-only Keeps.
IsActive
Keep:
IsActive
(
) →
boolean
Returns true
if the Keep is active in the session (not locked by another server).
Identify
Keep:
Identify
(
) →
string
Returns the string identifier for the Keep.
GetKeyInfo
Returns the DataStoreKeyInfo
for the Keep.
Reconcile
Keep:
Reconcile
(
) →
(
)
Fills in any missing data in the Keep using the data template.
AddUserId
Keep:
AddUserId
(
userId:
number
) →
(
)
Associates a userId
to a datastore to assist with GDPR requests (The right to erasure).
RemoveUserId
Keep:
RemoveUserId
(
userId:
number
) →
(
)
Unassociates a userId
from a datastore.
GetVersions
Types
interface
Iterator {
PageUp:
(
)
→
(
)
--
Goes to the next page of versions.
PageDown:
(
)
→
(
)
--
Goes to the previous page of versions.
SkipEnd:
(
)
→
(
)
--
Goes to the last page of versions.
SkipStart:
(
)
→
(
)
--
Goes to the first page of versions.
}
Grabs past versions of the Keep and returns an iterator to customize how to handle the versions.
"I lost my progress! Last time I had 200 gems!"
keep:GetVersions():andThen(function(iterator)
local versionInfo = iterator.Current()
while versionInfo do
local oldKeep = store:ViewKeep(player.UserId, versionInfo.Version):expect()
if oldKeep.Data.Gems >= 200 then
print("Found the version with 200 gems!")
break
end
versionInfo = iterator.Next()
end
end)
SetVersion
Types
type
Keep =
{
Data:
{
[
string
]
:
any
}
,
UserIds:
{
number
}
,
number
>
,
Releasing:
Signal
<
Promise
<
(
)
>
>
,
Saving:
Signal
<
Promise
<
(
)
>
>
,
Overwritten:
Signal
<
boolean
>
}
Allows for a manual versioning process, where the version is set and the data is migrated to the new version using the optional migrateProcessor
function.
DataKeep provides a version list iterator. See :GetVersions().
Returns a Promise that resolves to the old Keep (before the migration) This is the last time the old Keep's GlobalUpdates will be accessible before permanently being removed.
DANGER
Will not save until the next loop unless otherwise called using :Save() or :Overwrite() for view-only Keeps.
WARNING
Any global updates not taken care of in migrateProcessor
will be lost.
GetActiveGlobalUpdates
Returns an array of active global updates (not locked / processed).
GetLockedGlobalUpdates
Returns an array of locked global updates (processed).
WARNING
Lock updates can not be changed, only cleared after done being used.
ClearLockedUpdate
Keep:
ClearLockedUpdate
(
id:
number
) →
Promise
<
(
)
>
Clears a locked global update after being used.
DANGER
Passing an active global update id will throw an error & reject the Promise.