Roy_Mer
|
  |
| Joined: 13 Jul 2014 |
| Total Posts: 396 |
|
|
| 22 Aug 2016 12:01 PM |
Is there any way to compress a lot of important data which needs to be saved in a datastore and loaded efficiently?
Can JSON be used for this or are there any techniques to do so, if possible on Roblox?
|
|
|
| Report Abuse |
|
|
|
| 22 Aug 2016 12:10 PM |
| what kind of data is a very important part to this puzzle |
|
|
| Report Abuse |
|
|
Roy_Mer
|
  |
| Joined: 13 Jul 2014 |
| Total Posts: 396 |
|
| |
|
ByDefault
|
  |
| Joined: 25 Jul 2014 |
| Total Posts: 3197 |
|
|
| 22 Aug 2016 12:18 PM |
I always save all my data in a table, convert the table to JSON on saving and convert it back to a table on load.
local data = game:GetService("DataStoreService"):GetDataStore("TestData") local http = game:GetService("HttpService")
game.Players.PlayerAdded:connect(function(player) local pData = data:GetAsync(player.userId) if pData then pData = http:JSONDecode(pData) print(pData.SomeValue) end end)
game.Players.PlayerRemoving:connect(function(player) local pData = { SomeValue = 5 } data:SetAsync(player.userId,http:JSONEncode(pData)) end) |
|
|
| Report Abuse |
|
|
|
| 22 Aug 2016 12:21 PM |
| @ByDefault No need to do that anymore, datastores automatically convert tables into JSON. |
|
|
| Report Abuse |
|
|
Roy_Mer
|
  |
| Joined: 13 Jul 2014 |
| Total Posts: 396 |
|
|
| 22 Aug 2016 12:29 PM |
@while_loop, are you sure about that?
|
|
|
| Report Abuse |
|
|
|
| 22 Aug 2016 01:11 PM |
@Roy Yes, I currently do it in a game.
I used to have a module that converts tables into JSON before saving the data and converting them back into tables when getting the data back. |
|
|
| Report Abuse |
|
|
|
| 22 Aug 2016 01:17 PM |
| For some reason a lot of people don't know that DataStores convert to JSON before upload even though it says so on the wiki |
|
|
| Report Abuse |
|
|
|
| 22 Aug 2016 01:18 PM |
@Affect The didn't originally, and I think it was only quite recently that they changed it because I remember getting errors when trying to save a table to a datastore.
So, people just aren't informed. |
|
|
| Report Abuse |
|
|
|
| 22 Aug 2016 01:21 PM |
| But I remember learning about DataStores when they first came out and I thought I read that back then... maybe I'm misremembering. |
|
|
| Report Abuse |
|
|
ByDefault
|
  |
| Joined: 25 Jul 2014 |
| Total Posts: 3197 |
|
|
| 22 Aug 2016 01:25 PM |
| Does it really matter if you convert them to JSON manually lol |
|
|
| Report Abuse |
|
|
|
| 22 Aug 2016 01:26 PM |
| not practically, since json encoding is super fast, but it's an unnecessary step. |
|
|
| Report Abuse |
|
|
|
| 22 Aug 2016 01:27 PM |
| @ByDefault No but its pointless to do and adds useless lines to code. |
|
|
| Report Abuse |
|
|
ByDefault
|
  |
| Joined: 25 Jul 2014 |
| Total Posts: 3197 |
|
|
| 22 Aug 2016 01:29 PM |
| It adds 1 line of code total, not much lol |
|
|
| Report Abuse |
|
|
|
| 22 Aug 2016 01:32 PM |
I was accounting for loading the data in as well.
I don't see why you're arguing this. Its pointless code, you can't deny it. If you'd like to do it then you can but I'm just pointing out that there is no point. |
|
|
| Report Abuse |
|
|
|
| 22 Aug 2016 01:35 PM |
Idk about now, but when DataStore first came out each item in a table counted as one request because they were all saved separately.
|
|
|
| Report Abuse |
|
|
Roy_Mer
|
  |
| Joined: 13 Jul 2014 |
| Total Posts: 396 |
|
|
| 22 Aug 2016 01:35 PM |
So I can just save and load a huge table super efficiently now since it automatically converts to JSON?
|
|
|
| Report Abuse |
|
|
| |
|
Roy_Mer
|
  |
| Joined: 13 Jul 2014 |
| Total Posts: 396 |
|
| |
|
|
| 22 Aug 2016 01:40 PM |
I'd convert it to JSON first or find a way to not need to upload such a big table.
|
|
|
| Report Abuse |
|
|
Roy_Mer
|
  |
| Joined: 13 Jul 2014 |
| Total Posts: 396 |
|
|
| 22 Aug 2016 01:41 PM |
Well to be honest I could shorten some stuff to save them in 1 string but I don't need to convert to JSON since it's automatically apparently lol.
|
|
|
| Report Abuse |
|
|