|
| 28 Apr 2017 01:28 PM |
local ods = game:GetService("DataStoreService"):GetOrderedDataStore("UCRTime9")
function updateBoard(board, data) for k,v in pairs(data) do local pos = k local id = v.value local placesid = v.key local slot = game.Workspace['slot'..pos].SurfaceGui slot.ImageTest.Image= "h##################################################################################.placesid position = id end end
while true do -- wrap logic in pcall in case datastore request fails local success, message = pcall(function() local pages = ods:GetSortedAsync(false, 18) -- get data for first board local data = pages:GetCurrentPage() updateBoard(game.Workspace.slot[position].SurfaceGui, data) print("datastore loaded") -- check if another page of data exists if not pages.IsFinished then -- if so then get data for second board pages:AdvanceToNextPageAsync() data = pages:GetCurrentPage() updateBoard(game.Workspace.slot2.SurfaceGui, data) end end) if not success then print(message) end wait(10) end
I need to access id variable outside of the function updateBoard, how would I achieve this, I've tried allocation a variable to the local variable but when I reference this outside of the function it returns nil. |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2017 01:37 PM |
local id = nil
function updateBoard() id = v.Value end
Just know that you can only have one id at a time
|
|
|
| Report Abuse |
|
|
|
| 28 Apr 2017 01:42 PM |
local ods = game:GetService("DataStoreService"):GetOrderedDataStore("UCRTime9") local id = nil
function updateBoard(board, data) for k,v in pairs(data) do local pos = k id = v.value local placesid = v.key local slot = game.Workspace['slot'..pos].SurfaceGui slot.ImageTest.Image= "h##################################################################################.placesid position = id end end
while true do -- wrap logic in pcall in case datastore request fails local success, message = pcall(function() local pages = ods:GetSortedAsync(false, 18) -- get data for first board local data = pages:GetCurrentPage() updateBoard(game.Workspace['slot'..position].SurfaceGui, data) print("datastore loaded") -- check if another page of data exists if not pages.IsFinished then -- if so then get data for second board pages:AdvanceToNextPageAsync() data = pages:GetCurrentPage() updateBoard(game.Workspace.slot2.SurfaceGui, data) end end) if not success then print(message) end wait(10) end
Changed to this - problem is it returns attempt to concatenate upvalue 'id' (a nil value) |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2017 01:43 PM |
you have to capitalize the v in v.Value
|
|
|
| Report Abuse |
|
|
|
| 28 Apr 2017 01:47 PM |
| Ok, Just done that but its still returning nil value, does not return this value when variable called within function. |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2017 01:49 PM |
Actually, I'm not sure what you're iterating through, is this a free model?
|
|
|
| Report Abuse |
|
|
|
| 28 Apr 2017 01:53 PM |
Place here: https://www.roblox.com/games/752416863/UCR-Time-Capsule (I've uncopylocked it)
Not a free model but based off Roblox Ordered Datastore Example online |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2017 01:55 PM |
local x = nil function y x = "z" end y() print(x) --Prints "z"
~MightyDantheman~ |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2017 02:39 PM |
| Still no further foward - that doesn't appear to be working. |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2017 05:31 PM |
Whoops, I meant this:
local x = nil function y() x = "z" end y() print(x) --Prints "z"
--//
~MightyDantheman~ |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2017 05:36 PM |
u can just put
local vara, varb, varc...
the = nil is already interpreted |
|
|
| Report Abuse |
|
|