generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Pass variable outside of function

Previous Thread :: Next Thread 
electricfirestorm is not online. electricfirestorm
Joined: 18 Nov 2009
Total Posts: 133
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
ExtremeBuilder15 is online. ExtremeBuilder15
Joined: 01 May 2012
Total Posts: 3176
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
electricfirestorm is not online. electricfirestorm
Joined: 18 Nov 2009
Total Posts: 133
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
ExtremeBuilder15 is online. ExtremeBuilder15
Joined: 01 May 2012
Total Posts: 3176
28 Apr 2017 01:43 PM
you have to capitalize the v in v.Value


Report Abuse
electricfirestorm is not online. electricfirestorm
Joined: 18 Nov 2009
Total Posts: 133
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
ExtremeBuilder15 is online. ExtremeBuilder15
Joined: 01 May 2012
Total Posts: 3176
28 Apr 2017 01:49 PM
Actually, I'm not sure what you're iterating through, is this a free model?


Report Abuse
electricfirestorm is not online. electricfirestorm
Joined: 18 Nov 2009
Total Posts: 133
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
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
28 Apr 2017 01:55 PM
local x = nil
function y
x = "z"
end
y()
print(x)
--Prints "z"


~MightyDantheman~
Report Abuse
electricfirestorm is not online. electricfirestorm
Joined: 18 Nov 2009
Total Posts: 133
28 Apr 2017 02:39 PM
Still no further foward - that doesn't appear to be working.
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
28 Apr 2017 05:36 PM
u can just put

local vara, varb, varc...

the = nil is already interpreted
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image