Objective C classes for music play and interaction with the Game Center

I’m sharing the classes i have wrote to be able to interact from Codea and control the Game Center server responses with simple handles. You may also be interested in play mp3 music files.
For the moment i have implemented the highscores board and submission… next: achievement and then multiplayer with GC.
Files to add to the XCode Project:

Remember to add

//Game Center Functions:
//Play Music

in LuaState.m , then the definitions:

    //Game Center:
    int aGameCenter_start(struct lua_State *state);
    int aGameCenter_isGameCenterAvailable(struct lua_State *state);
    int aGameCenter_showLeaderboard(struct lua_State *state);
    int aGameCenter_reportScore(struct lua_State *state);
    //Play Music
    int playMusic(struct lua_State *L);
    int stopMusic(struct lua_State *L);

in OSCommands.h and the implementations:

static aGameCenter_Codea *CodeaGameCenter;

int aGameCenter_start(struct lua_State *state){
    NSLog(@"Starting Game Center");
    if (CodeaGameCenter==nil){
        CodeaGameCenter = [[[aGameCenter_Codea alloc] init] autorelease];
    [CodeaGameCenter start];
    return 0;

int aGameCenter_isGameCenterAvailable(struct lua_State *state){
    return [CodeaGameCenter isGameCenterAvailable];

int aGameCenter_showLeaderboard(struct lua_State *state) {
    [CodeaGameCenter showLeaderboard];
    return 0;

int aGameCenter_reportScore(struct lua_State *state) {
    [CodeaGameCenter reportScore:lua_tonumber(state,1)];
    return 0;

int playMusic(struct lua_State *L){
    [CodeaGameCenter playMusic:lua_tonumber(L,1)];
    return 0;

int stopMusic(struct lua_State *L){
    [CodeaGameCenter stopMusic];
    return 0;

in OSCommands.m

Check it out.

Now this is what I would love to see built in to the Main Codea app and the Runtime. Even if the main App can not interface, we could build some faux-display which hooks in while working on our apps and then it translated without issue into the runtime.

I hope this project eventually leads to also adding in Push notifications, iAd support, and many other of the normal iOS/Xcode functions.

TTL, please incorporate code like this :slight_smile:

I guess several feature requests that I suggest for Codea are already available within the runtime. Problem is that I do not have a Mac yet and I am unable to realize the possibilities that are there. Perhaps one day I will purchase an Apple developer’s license and a cheap iMac and learn Objective C (when I am closer to publishing my first app) just to see what may be possible with yet another new language.

Until then, I am really enjoying learning Codea/Lua and seeing the results on the screen from which I am programming (hacking) to/from.

This is probably best put in another thread but I wanted to let you guys/gals know that I am not sitting idle waiting for someone else to write my code (though examples are extremely helpful). I have been learning from practice writing code for a generic app menu system that consists of nearly 2500 lines of code and no actual game code yet.

I am working on a typical side scroller trying to figure out how to move the character left, right, jump, duck, and fire weapons and am having a blast through trial and errors (mostly errors). I do have an issue with very little instructions but I guess that helps to learn to be more logical.

Sorry but just wanted to chime in. Codea has been way too addictive that I have neglected nearly all of my 100+ apps.

Thanks TTL and all of the forum members for making this so much enjoyable.

Yeah, I’m sure a few are already in the runtime, but not within the Codea app itself. All in all, I think they should all be incorporated in to Codea itself to keep from having to do any altering of code to add functionality in the transition from Codea to the Codea Runtime for the App store submission.

Excellent additions, @juaxix. It might be nice to have these features available in the runtime only.

Note that we can not offer Game Center access from the main Codea app as Game Center is controlled by Apple on a per-app basis. So that would mean all Codea users would have the same leader boards, with the same scores. It would not make very much sense.

I was thinking that some kind of hook could be written in for the main Codea app that could catch the Game Center/MP3 code that could provide some kind of output for testing without it going off to the Game Center or anything else. Perhaps instead of outputting to the game center, it could output to a local setting or maybe even a global setting.

That way, one set of code would work on both, without having to require some post Codea alteration on the way out to XCode.

@Deamos you could actually arrange that yourself in Codea:

if myGameCenterFunction == nil then
    myGameCenterFunction = function( x, y, z ) 
        print("dummy function") 

Then when you link with the Codea Runtime Library, and provide a real implementation of myGameCenterFunction it will not use your dummy code (which might instead store your scores in local data, for example).

The problem with us providing specific functions is that we might not provide the exact functions your game needs — unless we wrap the entire Game Center API in Lua and keep it up to date. But that is not really a useful thing for us to do if it can’t even be used in the Codea app.

I don’t understand something:

  • 1. I will extract the file myProject.Codea from my iPad.
  • 2. I will change the source code of Codea Runtime with your code.
  • 3. I will unpack myProject.Codea
  • 4. I will replace from myProject.Codea, for example: sound() with playMusic(1 or 2 or any number) and then I will archive again myProject.Codea
I have three questions:
  • 1. What I wrote above is correct?
  • 2. Play MP3 files needs iOS Game Center?
  • 3. Where do I put my mp3 files so they can be found?
I ask because I have not tested this. I use macincloud.com and it moves a little hard.

You have to add the code i suggest here in the code generated with codea runtime script. If you only want to play mp3, just add the proper functions and connect them with external functions to the lua scripts…it’s easy thought

@juaxix I don’t have a Mac and have never coded besides codea.do you think it would be hard for me to place these files into my app once I get a Mac (soon) and compile my project using the codea runtime library. In short, what’s the difficulty level of this?

You dont need a mac. You can build a hackintosh or use an emulator like Oracle VM and install there osx and xcode, snow leopard and xcode for ios 4… , for example :wink:

what code do I use in my codea project to test the game center functions? I’m having a really hard time following along here because I haven’t ever tested my app besides within the codea app. what are you doing here? how would you link what I write in codea to Xcode. What functions? Sorry for spamming but I’m really confused by this.

hahaha!, Slow down @veeeralp !!.

We all know of your desire to finish your game, but running is not good to accomplish the task…

Check the Codea Runtime Library post, you will need to do some XCode tutorials, make some apps, games with Cocos2D, and then you will know how to use the code gifted here :wink:

sorry but I’m not going to have time to do tutorials and that sort of stuff. I don’t have a Mac and I dont have a Mac and I don’t want to download a virtualization tool for money. I’m going to use macincloud.com to make my game. I’m asking you because I have no idea what to do once I get xcode. Could you make a tutorial on it?

There are free virtual machine software @veeralp , once you start with XCode you may ask in this post


Would this still work? If CodeaAddOns is discouraged, would this be a viable alternative?