Game Center and storyboard

I have what is perhaps a really dumb question (or a few, actually) regarding Game Center implementation within an app that is set up in the Storyboard framework.

Does one need to do the initialization of Game Center in the main.lua (the one that starts the whole storyboard process rolling) or in the individual files that access Game Center?  For example, I am planning on having a Game Center button on my main menu and then updating game center based upon events that occur during gameplay.  Would initializing Game Center in the main.lua file and setting up the system.event listener there enable that to follow throughout the entire game?  Or do I need to include that code in each of the places where I am attempting to access game center?

Any help is appreciated.  I’m going to keep working on this, so I may figure this out on  my own, but thanks in advance for any suggestions.

All the best,

Alan

Initialize GameCenter in main.lua.  You still need to require the library in each storyboard module where you plan to make gameNetwork calls, but you only need to call gameNetwork.init() once in main.lua.

Rob

Thanks, Rob!  You’ve helped me out yet again.  You’re the best.

So, basically, I would include this code in my code in the main.lua file:

local gameNetwork = require “gameNetwork”
local loggedIntoGC = false

– called after the “init” request has completed
local function initCallback( event )
if event.data then
loggedIntoGC = true
native.showAlert( “Success!”, “User has logged into Game Center”, { “OK” } )
else
loggedIntoGC = false
native.showAlert( “Fail”, “User is not logged into Game Center”, { “OK” } )
end
end

– function to listen for system events
local function onSystemEvent( event )
if event.type == “applicationStart” then
gameNetwork.init( “gamecenter”, initCallback )
return true
end
end
Runtime:addEventListener( “system”, onSystemEvent )

And then, with the gameNetwork library included in each file that I intend to access Game Center, I can just use the gameCenter functions, correct?  That is awesome.  

I have to say, coming from a much less robust development environment, I am finding Corona to be amazing.  From the capabilities to the community, everything has been leaps and bounds better than what I was dealing with.

Thanks again,

Alan

That’s the gist of it.

Rob

Initialize GameCenter in main.lua.  You still need to require the library in each storyboard module where you plan to make gameNetwork calls, but you only need to call gameNetwork.init() once in main.lua.

Rob

Thanks, Rob!  You’ve helped me out yet again.  You’re the best.

So, basically, I would include this code in my code in the main.lua file:

local gameNetwork = require “gameNetwork”
local loggedIntoGC = false

– called after the “init” request has completed
local function initCallback( event )
if event.data then
loggedIntoGC = true
native.showAlert( “Success!”, “User has logged into Game Center”, { “OK” } )
else
loggedIntoGC = false
native.showAlert( “Fail”, “User is not logged into Game Center”, { “OK” } )
end
end

– function to listen for system events
local function onSystemEvent( event )
if event.type == “applicationStart” then
gameNetwork.init( “gamecenter”, initCallback )
return true
end
end
Runtime:addEventListener( “system”, onSystemEvent )

And then, with the gameNetwork library included in each file that I intend to access Game Center, I can just use the gameCenter functions, correct?  That is awesome.  

I have to say, coming from a much less robust development environment, I am finding Corona to be amazing.  From the capabilities to the community, everything has been leaps and bounds better than what I was dealing with.

Thanks again,

Alan

That’s the gist of it.

Rob