一个关于Roblox studio的问题,或者更确切地说,是关于dataStore的问题。如果您在输出数据:GetCurrentPage()时按点将值直接保存在脚本中:GetCurrentPage()-此值将被输出,但如果您通过函数执行此操作,则会保存该值,但不会在数据:GetCurrentPage()中显示。如何保存用户数据?
将值直接保存在脚本中:
PlayerPoints:SetAsync("Mars", 19)
local success, err = pcall(function()
local Data = PlayerPoints:GetSortedAsync(false, 5)
local WinsPage = Data:GetCurrentPage()
print(WinsPage)
end)将值直接保存在函数中:
local function givePointsPlayer(player, points)
local pointsOld = pointsStore:GetAsync(player.Name.."&"..tostring(player.UserId).."&"..tostring(os.date("*t").month))
if (pointsOld == nil) then
pointsOld = 0
end
print(pointsOld)
local success, err = pcall(function()
pointsStore:SetAsync(
player.Name.."&"..tostring(player.UserId).."&"..tostring(os.date("*t").month),
pointsOld + points
)
end)
end
EventEditPointsPlayer.OnServerEvent:Connect( function(player, points)
givePointsPlayer(player, points)
end)答案:answer
如何保存用户数据以便通过:GetCurrentPage()输出?
发布于 2021-04-05 20:06:41
如果您想从页面中获取数据,则需要编写一些代码来遍历每个条目和页面。下面是DevHub教程中的一个示例:
-- Sort data into pages of three entries (descending order)
local pages = characterAgeStore:GetSortedAsync(false, 3)
while true do
-- Get the current (first) page
local data = pages:GetCurrentPage()
-- Iterate through all key-value pairs on page
for _, entry in pairs(data) do
print(entry.key .. ":" .. tostring(entry.value))
end
-- Check if last page has been reached
if pages.IsFinished then
break
else
print("----------------")
-- Advance to next page
pages:AdvanceToNextPageAsync()
end
end有关更多信息,请参阅来自Roblox DevHub的本教程:https://developer.roblox.com/en-us/articles/Data-store
https://stackoverflow.com/questions/66945886
复制相似问题