Forgive me as I’m a noob to Coronium and Corona but when I send data back from the server using coronium.output how do I access the data I send back in the client. I can’t tell how to do this from the tutorials.
Thank you
Forgive me as I’m a noob to Coronium and Corona but when I send data back from the server using coronium.output how do I access the data I send back in the client. I can’t tell how to do this from the tutorials.
Thank you
Hi,
Coronium is event based, like a number of other Corona SDK methods. So, basically it works like so:
[lua]
mc:getObject(“objClass”, “objectId”, function( event )
print( event.result.some_value )
end)
[/lua]
http://docs.coronium.io/en/latest/client/DataObjects/#getobject
The “event” will hold the same as an “answer” table in cloud (http://docs.coronium.io/en/latest/devel/Answer/)
An incoming “event” has either a result key or an error, and errorString.
You can check the error first to make sure you have a valid result:
[lua]
mc:getObject(“objClass”, “objectId”, function( event )
if event.error then
print( event.error, event.errorString )
else
print( event.result.some_val )
end
end)
[/lua]
Most likely you’ll want to use the return elsewhere in your code. In that case you want to set up a closure and pass it as the callback like so:
[lua]
local callback
local username
callback = function( event )
username = event.result.username
end
mc:getObject(“objClass”, “objectId”, callback )
[/lua]
Another trick is to just call another function on the return to keep your application flow moving:
[lua]
local function startGame( username )
print(username…" is ready to play")
end
mc:getObject(“objClass”, “objectId”, function( event )
if not event.error then
startGame(event.result.username)
end
end)
[/lua]
Hope that helps.
Cheers.
Thank you for your help
Hi,
Coronium is event based, like a number of other Corona SDK methods. So, basically it works like so:
[lua]
mc:getObject(“objClass”, “objectId”, function( event )
print( event.result.some_value )
end)
[/lua]
http://docs.coronium.io/en/latest/client/DataObjects/#getobject
The “event” will hold the same as an “answer” table in cloud (http://docs.coronium.io/en/latest/devel/Answer/)
An incoming “event” has either a result key or an error, and errorString.
You can check the error first to make sure you have a valid result:
[lua]
mc:getObject(“objClass”, “objectId”, function( event )
if event.error then
print( event.error, event.errorString )
else
print( event.result.some_val )
end
end)
[/lua]
Most likely you’ll want to use the return elsewhere in your code. In that case you want to set up a closure and pass it as the callback like so:
[lua]
local callback
local username
callback = function( event )
username = event.result.username
end
mc:getObject(“objClass”, “objectId”, callback )
[/lua]
Another trick is to just call another function on the return to keep your application flow moving:
[lua]
local function startGame( username )
print(username…" is ready to play")
end
mc:getObject(“objClass”, “objectId”, function( event )
if not event.error then
startGame(event.result.username)
end
end)
[/lua]
Hope that helps.
Cheers.
Thank you for your help