Hi all,
I want to create a helper script to access my json data over my webpage. I would like to create another lua file to access this data, then use this data in my main.lua file. I want output to be actual time data from my URL instead of “i am not nil”
Main.lua
local jsonAccess = require("jsonAccess") print(jsonAccess["hereisdate"])
JsonAccess.lua
local json = require "json" local jsonClass={}; jsonClass.hereisdate = "i am not nil" local function networkListener( event ) if ( event.isError ) then print ("Network error!") else local jsonData = json.decode(event.response) jsonClass.hereisdate = jsonData["time"] end end network.request( "http://URL/json\_data.php", "GET", networkListener ) return jsonClass;
I am new to Lua and having a bit of issue figuring out how to deal with scoping. If I do my assignments in networkListener function, due to scoping, variable value outside of this scope stays unchanged. Eventually my network data access function never updates my local variables.
Should i be saving my data to sql or global variables instead?