Nov 272010
 

This tutorial covers adding OpenFeint achievements to your iPhone app using Lua and Corona.

Before continuing, please ensure you have completed Part 1 of the OpenFeint Tutorial and that you have added yourself as a test user, as described in Part 2.

*The rest of part 2 can be ignored entirely or you can come back to it later if you don’t want a leaderboard at this time; just ensure you have added yourself as a test user or this will not work.

Alright, let’s get some OpenFeint achievements into your app!

STEP ONE: We’re going to need to create at least one OpenFeint achievement in order to test this, so head on over to the OpenFeint site now and throw something together. It can be a real achievement or a test achievement as while it will not be able to be deleted once you have achieved it on your OpenFeint account, all details can be edited. Minimize the window, but don’t close it.

STEP TWO: Open up your main game file, this will be main.lua if you are not using director, or something like game.lua if you are, and paste the following code somewhere below where you’ve done your usual vital set up of a scene/screen and performed a check to see if we are on our device or the Corona simulator as explained in previous parts of this tutorial;

1
2
3
4
5
6
7
8
9
--------------------------------------------------------------------------
function Ach1000 (event)
if onDevice and score.getScore() > 999 then
openfeint.unlockAchievement(123456)
else
print("calling ach 1000")
end
end
timerAch1000 = timer.performWithDelay(2000, Ach1000, 0)

Now, I am using a timer – but I’ll get to that in a moment. First, check whether you are using the term “OnDevice” or “OnDeviceGO” and make sure this matches up with that. (I have used both in previous tutorials.)

As you can see, I’ve used a big label to identify what I’m doing – you don’t need it but if you have a lot of achievements (Happy Doodle Sushi Smile has 35 currently) you will find it helps to comment them clearly and keep them in a nice order.

I am using a timer here because this was my first real game with Corona and it made sense to me; my app runs fine. If you feel like you’re suffering though, or have a general aversion to timers, you could instead add this as a function when you change your score. For example, I could have said every time my hero eats a piece of sushi, (the point of HDSS,) if the score is >999 then unlock the OpenFeint achievement. It’s a matter of preference.

STEP THREE: Change the “123456″ above to your achievement ID, which you can see by opening the OpenFeint window that we minimized a moment ago, then change your function’s name (and the timer’s if you are using one) to whatever you feel appropriate. You may also want to change what is printed, or remove it entirely, again, a matter of preference.

STEP FOUR: Go to whichever event triggers your “game over” and add the following line of code as part of the function;

1
timer.cancel(timerAch1000)

Of course, you’ll want to use your own timer’s name if you decided to change it, or if you didn’t need a timer you can skip this step entirely.

STEP FIVE: Compile it and test it on your device!

And we’re done!

This is not a complicated thing to do and it shouldn’t cause you any headaches, particularly if you have successfully completed parts 1 and/or 2 of my OpenFeint tutorials.

If you have problems, as usual, I implore you to get in touch – I’m no where near as advanced as a lot of people when it comes to Corona or Lua, however I do love to help whenever I can.

*As a point of interest for those wondering, with 35 achievements all using timers I haven’t had any issues – I mentioned the figure above, but wanted to clarify.

I look forward to my next tutorial, although I currently have no idea what exactly it will be about!

Peach Pellen :)

PS – A belated happy Thanksgiving to those of you in America. I am jealous of the copious amounts of turkey that were undoubtedly consumed and that I myself only get to eat once a year at Christmas and am looking forward to immensely in *checks app made with Corona exclusively for this purpose* 26 days, 22 hours and 51 minutes!

Like this post? Subscribe to the monthly newsletter!

 

  6 Responses to “Adding OpenFeint To Your iPhone App – Part 3”

  1. So strange, I have done the way I can maybe achievements will popup once you fill out the iOS Settings tab in OpenFeint webinterface once the app is on Appstore. Thanks anyway.

  2. No matter what I do the Achievements does not show up in the OpenFeint Dashboard on the device. What can be wrong? It sets the achievements correct and the leaderbords work great.

    Please help

    • This sounds like it is something on OpenFeint’s end and not on Corona’s, to me. I haven’t built an OpenFeint app in the past week so I can’t be certain one way or the other, however their interface is handled by them.

      Sorry!

  3. Hi Bruce,

    OpenFeint does NOT work in the simulator. I’ve stated this in previous tutorials and it is also made clear on the Ansca website.

    When you have implemented OpenFeint you need to build for your device to test it; there is no other way.

    Peach

  4. Hi – Peach

    I am having hard time establishing a simple highscore system for my game. It is director class and I followed the “new” openfeint code that you wrote, and all I get is the image of the openfeint button in my simulator, but it does not work, it is just there. Is the button suppose to lead to a dashboard after I have completed the first tutorial or after — it doesn’t matter either way because the button is not opening. Please…please…please give me some advice as I have been spending hours trying to figure out a simple database for a single highscore system to add to my game. PLEASE HELP!

  5. [...] Part 3: Adding OpenFeint Achievements to your App [...]

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.