Game Development Community

[SOLVED] GameCenter functions not executing in 1.5

by Pedro Vicente · in iTorque 2D · 11/27/2011 (6:02 pm) · 8 replies

iTorque 1.5
iOS (4.3, 5)
XCode 4.2
Mac OS Snow Leopard


This makes no sense to me.

I added this function in script (to the Rainy Day sample)

initGameCenter();

but the console shows this error:

Quote:
scripts/game.cs (132): Unable to find function initGameCenter

I put a breakpoint in XCode in the source function

ConsoleFunction(initGameCenter, bool, 1, 1, "() Initialize Game Center and authenticate the playern"
                                            "@return True if Game Center was successfully initialized, false if there was an error")
{
    if(isGameCenterAvailable())
    {
        gameCenterManager = [[GameCenterManager alloc] init];
        [gameCenterManager authenticateLocalUser];
    }
}

that is not triggered at all.

This works in 1.4.1 with the community resource for GameCenter (that I believe is the same as the 1.5 GameCenter code)



#1
11/27/2011 (6:20 pm)
Hey Pedro, Do you have the game center option checked in your iTGB project?

#2
11/27/2011 (6:38 pm)
@Ray

I am not aware of such option. Is this a iTGB Editor setting?
I don't use the iTGB Editor at all.

Also, I am not seeing what such option would accomplish. This should be a no-brainer: an existing Console function in the source code that is called in script;

also the official docs for GameCenter do not mention any game center option.

they just mention to add this piece of code

Quote:
In projectFiles/scripts/game.cs, add the following to the bottom of function startGame(%level):

if($platform $= "iphone" || $platform $= "ipad" || $platform $= "iphone4")
{
// Initialize Game Center
initGameCenter();
}
#3
11/27/2011 (7:29 pm)
Solved

So, it turns out that the source code file GameCenter.mm is enclosed with

#ifdef TORQUE_ALLOW_GAMEKIT

so, by default, the source code is not even compiled; not sure what's the goal of this
#4
11/27/2011 (8:43 pm)
@Pedro


It is in the editor, under Project -> iOS Feature Builder.

I haven't actually used it yet, but I have used the 'enable rotation' checkbox, which does control wether rotation works or not.

I am sure that anything you change in the editor effects some other config file, like the managed & level data blocks do, but I am not sure exactly where it goes.

Looking in the engine code at : isGameCenterAvailable(), it looks like we need iOS 4.1, and a player

gamecenter.mm has this for the first line: #ifdef TORQUE_ALLOW_GAMEKIT looks for a macro definition of something named TORQUE_ALLOW_GAMEKIT. This flag is defined in T2DBuild.xconfig as: IT2D_EDITOR_FLAGS = TORQUE_ALLOW_GAMEKIT

when you are in the compiler pre processing section of the target's build settings, you see the $(IT2D_EDITOR_FLAGS) is a variable in the list which should define the macro.


I just ran through, added game center, and now when I run my game, it displays a window on my iPad asking me to sign into game center sandbox

Hope that helps!

#5
11/27/2011 (8:57 pm)
@Ray

Thanks.
Since I like to keep things simple and do not use the iTGB editor, I solved this by adding this line at the start of GameCenter.mm

#define TORQUE_ALLOW_GAMEKIT
#ifdef TORQUE_ALLOW_GAMEKIT

:)

Still, I do not see the practical advantage for a user or developer to have that iTGB option to allow GameCenter to be compiled or not (I guess that by checking the option in the editor will add the macro to the file you mentioned).
#6
11/27/2011 (8:59 pm)
@Pedro,

Since every project you have uses the same code base, I believe the checkmark is a way to decide if you want game center available for a specific project

Congrats on getting it working!
#7
11/27/2011 (9:08 pm)
@Ray

Quote:Since every project you have uses the same code base, I believe the checkmark is a way to decide if you want game center available for a specific project

sure, I understand that. My point was what would be the downside of every project always having the GameCenter code compiled in the executable? In another words, if the TORQUE_ALLOW_GAMEKIT macro did not exist at all?
#8
11/27/2011 (11:18 pm)
well if its present you have to use it, that would be a reason.
requiring it (hence removing iPhone 3G from the supported device list) and not using it is a rejection reason on the AppStore