Last active
December 27, 2015 01:08
-
-
Save SimonRoblox/7242348 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Overview | |
+ We're providing new Data Persistence API, which lets you store some data | |
between server runs for ROBLOX places | |
+ Significant improvement over previous API, including: | |
- Arbitrary global data, not just per-playaer data | |
* Allows to subscribe to updates made by other instances! | |
- Guaranteed saves - as soon as call returns, data will not be lost | |
- In future, will allow sharing this data between different places | |
- Saves arbitrary lua tables | |
* Setup | |
+ To access it, open place from website (for example, from Start Page->My Projects) | |
+ WARNING: call from studio will affect data server sees, | |
so it's higly advised to have a separate test place! | |
+ Doesn't work in Play Solo yet, have to be Test Server or lua command line in Studio | |
* Accessing data persistence: | |
ds = game:GetService("UniverseService"):GetGlobalDataStore() | |
* API: | |
+ All action APIs on DataStore yield(as shown by Async suffix) | |
+ All keys are global per-place, not per player | |
+ GetAsync(key) - returns value | |
+ UpdateAsync(key, function(oldValue) return newValue; end) - to update a key, | |
you need to provide function that receives old value and returns new one | |
- This function can be run multiple times in case of conflict, so make sure you use oldValue | |
- To cancel update, return nil | |
- If key doesn't exist, will receive nil | |
+ IncrementAsync(key, delta=1) - increments value for a particular key, returns incremented value | |
+ SetAsync(key,value) - sets value. Very dangerous, since it can overwrite data from another instance. | |
Almost always using UpdateAsync is preferred | |
+ OnUpdate(key, function(value) end) - subscribe for key change. Change could come both from this | |
instance or other instances | |
- Returns connection, like event would | |
+ value can be number, boolean, string or lua table. ROBLOX types like Instances, Vector3, etc are not allowed | |
* Example: | |
ds = game:GetService("UniverseService"):GetGlobalDataStore() | |
ds:GetAsync("mykey") -- will return null | |
ds:UpdateAsync("mykey", function(oldValue) return oldValue == nil and 4 or nil) -- If key doesn't exist, create it, otherwise cancel update | |
ds:IncrementAsync("mykey",-2) -- will return 2 | |
ds:UpdateAsync("mykey", function(oldValue) return oldValue*2; end) | |
ds:GetAsync("mykey") -- will return 4 | |
ds:OnUpdate("mykey", function(value) print(value) end) | |
ds:SetAsync("mykey", 10) -- will print 10 |
Finally!
roaring crowd of applause
"+ OnUpdate(key, function(value) end) - subscribe for key change. Change could come both from this
instance or other instances "
Is it going to call the function with the old value or the new value?
Yaaaaay. Finally!
Mother of God...
Simon is best admin.
On a more purposeful note, how often would we be able to send requests without putting a toll on the servers?
Nergasm.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
:D