It looks like you're new here. If you want to get involved, click one of these buttons!
EDIT: Since the new Codea runtime in v2.1, these libraries no longer work. If you do make a fork of my library, please leave a link below and I'll add it up here.
Hello,
I've been putting it off for a while: Here's all the Objective-C libraries I've made for StackIt.
- TestFlight
- GCAddOn (This is better garbage collection for Lua)
- GameCenterAddOn
- LocationAddOn
- SharingAddOn
- AppDelegate
Please get the code from the actual source code of my game, StackIt, here.
1. Place the AppDelegate files in ProjectRoot / [your project name]
2. In AppDelegate.mm, put your project name in and your TestFlight key in
3. Place all other files in ProjectRoot / [your project name] / Addons
4. Tada!
1. Go to AppDelegate.h and delete the line that says #import "filename.h"
2. Delete the line that is @property (strong, nonatomic) fileclass *vartitle;
3. Go to AppDelegate.mm and delete the lines that say this:
self.vartitle = [[classname alloc] init];
[self.viewController registerAddon:self.vartitle];
And then you're golden.
- This is a live thread. I'm not done with these and I'll be posting updates.
- GameCenter and sharing only work on iOS 6, not 5. I'll be fixing that later.
- If you use this, all I ask is that you give me credit.
- I created my own GameCenter because it doesn't use deprecated APIs, you can publish to custom leaderboard names, and you can show GameCenter banners
- Make sure you enable GameCenter capabilities
- My sharing file can also save to the camera role
- Right now my sharing API only lets you share photos, but that'll change
- Any other questions/requests/changes? Want to know how to do something I did in StackIt? Let me know.
Enjoy!
Comments
Thanks for sharing! These will definitely come in handy once i migrate my project to Xcode / Codea Runtime
@JakAttak - No problem.
@Zoyt same for me thanks! (although i think i wont start publishing app befor 6-9 months.. But then it will quite help me!
I just finished the ability to compose HTML email in-app (with a popup), ability to view other apps inside your app, and ability to go to the review link.
Now I'm working on alerts with multiple options and callbacks.... Probably one of the more suggested features in Codea. Trust me, it's not easy... Not to mention it's 2:30 AM here.
It's now 6:15 AM... I'm almost done, one last bug. I had to learn all sorts of crap about the Lua C stack (it's horrible.) So I won't be posting the libraries tonight. Probably in a while.
Thanks!
I finished the library. Now I just need to make it compatable with the current "alert" API and handle errors.
I'm looking into making a UI elements library. We'll see how that goes... If I do it.
Sounds interesting
Hey there,
Alright, I'm at the point that i transferred all my stuff to Xcode and am trying to add these great plugins to the mix. I have a few basic questions though :
Thanks a lot, I'm excited to see how this works!
@Rodolphe, yes comment any code for the addons you dont include from the appdelegate files.
To call Game Center look in the add-on .m files where the functions are registered as lua functions - those are the names of the functions you can call directly from Codea code.
Thanks @JakAttak. Also, @Rodolphe, you can look at my latest repository, my game StackIt, which uses all these libraries. You can see what I do there. Just search the all the Lua code for "gamecenter". That will who you everywhere I use the library.
Thanks @JakAttak and @Zoyt. I can't see StackIt in your repository, did you release the code already?
@Rodolphe - It's not in that repository (and that's not even a repository anyways), it's in another repository here: https://github.com/Zoyt/StackIt
Hope that helps!
Thanks a lot Zoyt, I'll try and get game center to work in my game (credit is good, if I ever manage to make it work?)... Cheers!
Ok, I tried adding Game Center capabilities tonight. I:
1) turned on GC capability in xcode,
2) I added the m and h Game Center files in Addons directory
3) I added the new AppDelegate files
4) I inserted "authenticatePlayer()" at the beginning of setup(), "showGameCenter()" in the menu, when players press the GC button, and "reportScore(hscore,"Highest elevation")" when a game is over and the best score has been beaten
I'm getting this message, do you think I missed something?
https://dl.dropboxusercontent.com/u/73950/error GC.PNG
Thanks!
Hi @Rodolphe, this is ot, but there's a little typo. Developed, not developped
Oh thanks for the typo!
Sorry, what do you mean "this is ot"?
I meant that my comment was off topic
with regards to the question you've originally made, sorry for not saying that in the first place @rodolphe
Oh I'm sorry, English is not my mother tongue, obviously, and I tend to stumble on this kind of things...
thanks again for the heads up on the typo!
@Rodolphe - Lucky for you, easy fix. This simply means that your provisioning profile doesn't have GameCenter enable. So, to fix it, simply go to Xcode, then click on your project in the sidebar, make sure your app is selected as the target (which it probably is by default), then click "Capabilities" in the tab bar above the content. Finally, flip the switch on GameCenter. If that didn't make sense/doesn't work, LMK. I have another solution if this doesn't work.
Thanks! actually, it's activated, what would be your other solution @Zoyt?
@Rodolphe. I think I might be able to help. Are you calling the
showGameCenter
together withauthencatePlayer
? Because that might cause that issue.@Zoyt. Your add ons are really helpful, but I think I'm doing something wrong. The Game Center log in will show up in the simulator, but I can't log in and see the test leaderboards I have made.
EDIT: Never mind. I just never updated the App ID.
Thanks @YoloSwag, should I use only either showGameCenter or authencatePlayer ?
But maybe I didn't update the app id either, where should I do this?
@Rodolphe. I use authencatePlayer at the beginning, and thats it. When you want to show the leaderboards I then would assume you use showGameCenter, but i haven't tried this.
And you can update your App ID under the certificates page in the member section on the Apple dev website. However, i am still having problems with the logging in part.
EDIT (This contains the answer to your question): This was actually fixed by making a sandbox account. I reset my iPad, and it prompted me to make a new account.
To get rid of that error, try putting
authencatePlayer
in setup. This will allow the banner to pop up if they're already signed in, or prompt them to log in if they're not already. Hope this helps! I'm learning as I go along.If you have a button that pulls up game center, add this function somewhere within the parameters of that code:
showGameCenter()
. That will pull up any leaderboards you have.Sorry for the long explanation.
Still no luck... I'm wondering now, something really obvious I might have overlooked : should I create an app in itunes connect, then a leader board, in order to to be able to connect to it from my app while still in development?
@Rodolphe - Yes, that was one of the other things I was going to suggest. Try that. I think that's your issue.
@Zoyt. Does
showGameCenter
automatically call the leaderboard option set up in iTunes Connect, or does the leaderboard ID need to be added?@Rodolphe, yes you do need to have created the app in itunes connect
@YoloSwag - Not quite sure what you're asking, but you do have to call authenticatePlayer in the main function. Then, when the user wants to see the leaderboards, you call the showGameCenter function.
Edit: Sorry, I misunderstood your question. You can't (at this time) pass anything into the function, so it just goes to the default leaderboard.
@Zoyt. When I'm reporting a score to Game Center, am I supposed to put a variable within the parenthesis of
reportScore
? Because when I do put my scoring variable the app crashes.Thanks @JakAttak and @Zoyt, I'll try that...
@YoloSwag - Make sure you're also including the GameCenter leaderboard along with the score. i.e.:
reportScore(self.score,"highscore")
You can find the leaderboard IDs on iTunesConnect.
@Zoyt, thanks. Now I can see the test scores!
@Zoyt, @JakAttak, first-timer concern here... I'm wondering if I understood you well as far as creating the app in iTunes connect in order to test Game Center capabilities.
When creating the app, Apple asks me about all kind of material and information in order for them to review and publish the app. Off course, I'm not ready to get it reviewed, and much less published for that matter.
How does that work? should I go ahead, and I will later have an option to tell them not to review the app yet?
Cheers!
@Rodolohe, yes it is a slightly annoying system, you have to provide some of the details such as a screenshots - but don't worry because it will not put it into review yet and you can change all that info later.
Ok, thanks a lot @JakAttak!
Alright, it seems to work in sandbox mode in the simulator! Thanks! Also, is it possible to send achievements to game center, @Zoyt?
@Rodolphe, you would have to add your own functions to add that functionality.
Ok, I'll pass it for now, Objective C is still a little intimidating to me
I'll report back here if I manage anything...
@Rodolphe, I just gave it a go and I think I have some code that does what you want.
In GameCenterAddOn.h add these lines:
with the other similar lines underneath this one:
@property (weak, nonatomic) CodeaViewController *codeaViewController;
In GameCenterAddOn.m add these lines:
with the other similar lines in this function:
- (void) codea:(CodeaViewController*)controller didCreateLuaState:(struct lua_State*)L
then add this block of code:
anywhere with the other functions (i placed it after the reportScore code)
This will give you two new lua functions
reportAchievement
andshowAchievements
showAchievements
should bring up the Game Center view showing the achievements.reportAchievement
is called like so:reportAchievement(identifier, percentage)
whereidentifier
is the achievement identifier for the achievement you are updating, andpercentage
is the percentage complete (so for example if the achievement was kill 5 bosses, and you killed one bosspercentage
would be 20)I haven't tested this code (I don't have an app with achievements) so let me know if it works or doesn't.
Oh my... oh my... I can't believe it... I'll get back to you with results
it doesn't seem to work right now. I call reportAchievement as such:
where the achievement I want to award is:
https://www.dropbox.com/s/n2nxh67clrqj1fy/Capture d'écran 2014-07-31 15.22.08.png
@Rodolphe, I'll take a look. How long ago did you register the achievement?
A few hours, at the same time as the leaderborad, which works. Something else: calling showAchievements() works as expected !
Oops. I made a typo. it isn't passing the percentage, it's passing the identifier for both variables.. fixed above.
replace this line
[gameCenterAddOnInstance reportAchievementAction:[NSString stringWithCString:lua_tostring(state, 1) encoding:NSUTF8StringEncoding] percentComplete:(int)lua_tointeger(state, 1)];
with this:
[gameCenterAddOnInstance reportAchievementAction:[NSString stringWithCString:lua_tostring(state, 1) encoding:NSUTF8StringEncoding] percentComplete:(int)lua_tointeger(state, 2)];
hopefully that fixes it for you.
it wooooorks!!! All of this is quite amazing, I must say... thanks so much
@Rodolphe, glad it works
Another question already...
I get get an error "attempt to call global 'sendTweet' (a nil value)" when using:
Is this what you, @Zoyt, means when you write "Right now my sharing API only lets you share photos, but that'll change"?
@Rodolphe, that means that the function
sendTweet
does not exist.I believe his addon supports the functions
tweetPhoto
andfacebookPhoto
only.Thanks @JakAttak for answering those questions. You're the new Obj-C guru here.
Anyways, @Rodolphe, are you sure you included the add on completely?
Make sure you have
@property (strong, nonatomic) SharingAddOn *sharingAddOn;
in AppDelegate.h andself.sharingAddOn = [[SharingAddOn alloc] init]; [self.viewController registerAddon:self.sharingAddOn];
in AppDelegate.mm.Edit: Also, make sure you're using the one from my StackIt repository, not my snippets off GitHub.
Edit #2: To attach an image to the Tweet/FaceBook post, just add a second argument with the image.