Stumped on simple Variable Scope

local jsonApp = require "mydata"; local json = require "json" jsonApp.request = "test"; jsonApp.decode = ""; local function networkListener( event ) if ( event.isError ) then print( "Network error!") else if (event.phase == "ended") then jsonApp.request = event.response; end end end -- Access Google over SSL: network.request( "http://ip.jsontest.com/", "GET", networkListener ) print (jsonApp.request);

So here’s a simple Web Request code with Json parser utilized with Corona’s own examples to not use global variables.  This is all copied and pasted.  My issue is jsonApp.request is becoming a local variable within the callback function networkListener and the final print is still printing “test”. I’ve been away from lua for 2 years and I never remember running into this problem in the past.  Any help would be great.

You have network.request  that calls the URL and waits for a response, when it gets it, it calls the networkListener function, meanwhile the program goes to the next line and jsonApp.request has not been reassigned yet.

Thank You, Don’t know why I didn’t see that it was Asynchronous.  Could have spent that debug time building a response delay.

You have network.request  that calls the URL and waits for a response, when it gets it, it calls the networkListener function, meanwhile the program goes to the next line and jsonApp.request has not been reassigned yet.

Thank You, Don’t know why I didn’t see that it was Asynchronous.  Could have spent that debug time building a response delay.