Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to browse Data Store? (or put keys into table)

Asked by 8 years ago

How can I browse Data Store. For example, I have a Data Store:

key0 value0 key1 value1 key2 value2

Can I somehow put all keys in Data Store to the table to edit it with scripts?

1 answer

Log in to vote
0
Answered by 8 years ago

Yes, but you will need a separate request for each key.

local ds = --[[initialize datastore here]]
local t = {}
local keys = {"key0", "key1", "key2"}
local numOut = #keys
local errorOccurred = false
for i = 1, #keys do
    coroutine.resume(coroutine.create(function()
        local key = keys[i]
        local success, value = pcall(function() t[key] = ds:GetAsync(key) end)
        numOut = numOut - 1
        if not success then errorOccurred = value end
    end))
end
while numOut > 0 do wait() end
if errorOccurred then
    warn("Error occurred. Message: " .. errorOccurred)
    --Deal with the error here
else
    --Can use 't' at this point
end

Notably, you cannot browse a datastore's keys unless you're using an OrderedDataStore (which has the limitation of integer values only); you have to know what keys you're using in advance.

0
This is not what I want. It writes keys like key1, key2, key3. That was an example. In mine DS keys named differently. NAUSHNIK52 0 — 8y
0
Edited to be more general chess123mate 5873 — 8y
Ad

Answer this question