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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
| |
|
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
|
  |
| 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
|
  |
| 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 |
|
|