generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: What's the difference between Set and Update with datastores

Previous Thread :: Next Thread 
OldGoldie is not online. OldGoldie
Joined: 17 Aug 2010
Total Posts: 8210
08 Oct 2014 08:19 AM
SetAsync works fine for me, what's the difference?
is it the same thing, like the way to call it?
ds:UpdateAsync("example"..player.Name, "pringles")
Report Abuse
DrMathematica is not online. DrMathematica
Joined: 29 Aug 2008
Total Posts: 27268
08 Oct 2014 09:46 AM
SetAsync is like a direct SQL UPDATE statement. It just overwrites whatever is there.

UpdateAsync will get the current value of the key first, and run a transformFunction (second argument) before updating the key.
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
08 Oct 2014 10:16 AM
^

Oh,

Do not use SetAsync if you don't have to. ALWAYS use UpdateAsync if you can, why? The wiki and many RbxDevs says we should do this because apparently to much of overwriting the data will mess up with other data.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
08 Oct 2014 10:18 AM
SetAsync will suffice for writing at the end of a session and stuff, but you need UpdateAsync if you're going to use GetAsync alongside it (UpdateAsync = GetAsync + SetAsync) because GetAsync caches and can cause overwriting of data you may have wanted to keep
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
08 Oct 2014 10:19 AM
I never use updateasync. If you need to change the previous values I do:

local data = game:GetService("DataStoreService"):GetDataStore("Example")
local old = data:GetAsync("Points")
data:SetAsync("Points", old+1)
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
08 Oct 2014 10:19 AM
You know what, I just realized mine would be heavier on the request limit.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
08 Oct 2014 10:21 AM
local data = game:GetService("DataStoreService"):GetDataStore("Example")
local old = data:GetAsync("Points")
data:SetAsync("Points", old+1)

Is better written as

local data = game:GetService("DataStoreService"):GetDataStore("Example")
local old = data:UpdateAsync("Points", function(old) return old+1 end)

Simply because it uses less requests, and isn't subject to the same problem of caching as GetAsync is.
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
08 Oct 2014 10:23 AM
Damnit lunate, was going to rewrite it in UpdateAsync form

qq
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
08 Oct 2014 10:24 AM
So the method "UpdateAsync" automatically runs the function with the argument of the old value, correct?
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
08 Oct 2014 10:26 AM
Yep.
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
08 Oct 2014 10:28 AM
Alright, I never really looked into how that function worked, so I just shied away from it.
Report Abuse
OldGoldie is not online. OldGoldie
Joined: 17 Aug 2010
Total Posts: 8210
08 Oct 2014 11:53 AM
So, I should replace all my SetAsync to Update?
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
08 Oct 2014 12:14 PM
Not unless you have to.
It's perfectly reasonable to use SetAsync, unless you're using them very closely with GetAsync
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image