Jan 262011

This video (yup, it’s a video) will give you a brief rundown on how to add a score to your app using a custom font for numbers.

I don’t want to hear one mean thing said about my voice; don’t make me even more paranoid about talking to people. Plus, if I progress from here maybe when you need help I can Skype you with voice and not just text if I eventually realize no one is going to mock me. (Don’t hold out on that, though.)

Download the project here.

If you like it, please feel free to give me your money. I will graciously accept it. ;)

Enjoy, and let me know if you know the original creator of this score file we’re using here – I have tried countless times to find out with no luck.

Peach Pellen :)

Like this post? Subscribe to the monthly newsletter!


  41 Responses to “How To Add A Score To Your iPhone App”

  1. Hi Peach! Another great help from you, thanks a lot!
    I’ve successfully tried “score” in my game, it lets me have a much more personal and stylized look!

    I have just one question. I need to keep track of several different scores. Imagine a running game, where you must display distance, ammo, coins/money, enemies killed, etc…
    Is there a way to do this with this module? Cause i believe i can’t do it without modifying the code (or at least duplicating it), but maybe (surely) i’m wrong.

    Anyways, this module is awesome!! Thank you Peach.

    • Hey Fito – this would need duplicating with a new name. (Sorry for the late reply, am currently in the US and as such am not checking comments as regularly as I do when at home.)

  2. I need some help—
    I need to create score for game, then i need the application to tell add scores, i have tried everything and cannt find a way to do this, plz provide me some sample if you can so that it can make me undetstand better.
    pls help me.

    • Hey Jameel, post in the Ansca Mobile forums with more details and your code. This shouldn’t be too hard to figure out :)

  3. It’s possible to insert score in a group? Because the score appears at background and i need it to be at front.

    Thank you

  4. [...] – If you would like to expand your understanding of the score method that I am using, this score tutorial should [...]

  5. how can i round my score (which depends on at which y coordinate you destroy a ball) to 0 decimals?

  6. Hrm, it sounds a bit odd. If you want to email me your project I can try to take a little look for you in the next day or two.

    If not I’d suggest removing the code and readding it carefully to ensure it is all in the right order and you aren’t missing any images you need. (0-9, scorebg, space.)

  7. Yeah I dropped the score.lua into my project folder. I copied the main.lua file into my game’s level code. I’m starting to wonder if I wasn’t supposed to do that. It’s in the same .lua file of my game with all the code of my game.

    P.S I’m requiring it with score = require (“score”) in my game’s code, not a separate file.

  8. Hey Danny,

    Uhm, have you required score.lua correctly and made sure it is in the file? Something is missing.

    How did you require it?

  9. Hey Peach,
    I wanted to use your code (not your graphics ;) and my graphics to make a score field but I’m having some trouble.
    I dropped score.lua into my folder and puled the code from main.lua and I get errors. I’m posting the errors of the code. /Desktop/Adam’s Apple – Fixed/L25.lua:41: attempt to call field ‘getInfo’ (a nil value)
    and then I delete that line of code and then…
    /Desktop/Adam’s Apple – Fixed/L25.lua:42: attempt to call field ‘init’ (a nil value)
    and then I delete that line of code and then…
    /Desktop/Adam’s Apple – Fixed/L25.lua:43: attempt to call field ‘setScore’ (a nil value)

    So I’m getting a lot of errors and I don’t know why. I deleted the parts of the code to see if it was just one part but it wasn’t. Also, I didn’t modify anything in score.lua so it shouldn’t be a problem there.



  10. Hi Peach-
    First of, that was an awesome tutorial and your voice was wonderful. Don’t be so shy about everything. Keep up the good work and just keep going?

    Question for you and others, what’s the best practice of saving score in Corona or in mobile devices in general? saving every seconds/minutes or based on the event that get you the score? saving where? filesystem or db? how would we handle the scoring if the user quits the game by pressing the home button or answers a call?

    • Thank you Saidul :)

      For the best practice when it comes to saving it really depends on the kind of game you’re doing. If you have levels then at the end of the level may make sense. You do NOT need to save the score when the user presses the “home” button or answers a call provided you set exit on suspend to false. You can do that by putting this one line in your build.settings file;

      UIApplicationExitsOnSuspend = false

      Then it will continue from where they left off if they resume the game. :)

      PS – Best way I’ve found for scores is the Ice library, made by Graham Ranson, they creator of Lime.

  11. How can we use Timer as a score to add it to a game..

    • I already answered your forum post with a link to a tutorial of mine that explains how to do that EXACT thing.

      If you use SEARCH it will also come up with that tutorial.

      If you do not wish to use SEARCH you can click on “APIs” on http://anscamobile.com/ and then read about timer.performWithDelay() which is what you would use to add points to the score every X seconds/minutes/etc.


  12. Hi Steve,

    There are different ways of handling the score.

    To start – I have no idea what a “subView” is, I’ve not encountered the term – but based on the “/play.lua” I assume it must mean you’ve used director to go to your Play screen. (Sorry if I’m wrong!)

    Now you don’t put it in the director group – instead put everything ELSE in the director group.

    If you do that it shouldn’t disappear – if it is yeah, take a look at Ghosts Vs Monsters – it’s a great demo for learning a whole host of useful stuff.

    If you still can’t get it let me know.

    Peach :)

  13. Hi Peach, and thank you very much for all the lessons.

    I’m a complete noob in Corona (about 3days old)

    I’ve managed to create a menu system for a game concept using the director.lua.
    My problem is when I’m in a subView / play.lua the score appears breifly then disappears.
    I’ve tried to use the common display linker localGroup:insert(score)
    But as expected this crashes the app when called.

    Any ideah how I could work around this?
    Or maybe I should take another look at the ghosts vs monsters sample.
    I think there using director also.

    Thanks in advance.


  14. peter,

    I’m a woman – so thanks, I think.

    As to the code; no, you’re mistaken. Here’s why; hearing audio instructions, seeing it being written at the same time while also writing it down YOURSELF is a faster way of learning than looking at code which you will then, most likely, copy and paste.

    I have made it available to download in a file, as you can see by the huge download link in the post – so it isn’t like it’s not available – only that I am encouraging people to write it out themselves as that is, as I said above, the best way to learn anything.


  15. Your voice depends of who you are.
    If you are a woman, sounds sexy and sensual.
    If you are a man… well… might sound weird, unless you are a 14 years old kid, but if you are a thought bearded man.. it is weird.
    Sorry but your name doesnt tell me your gender

    Anyway, if you are just going to type and say what you are typing without further explanation, better just post the code there.. right?

  16. It does not, this is simply a way to display a score with a custom font, basically.

    If you want to save scores you need to actually write them to a file; I’ll do a demo on that in the future but in the meantime there’s an example in the CoronaSDK Sample Code folder on your computer :)

  17. Great tut. Does this also have a built-in save score system?

  18. [...] have successfully coded an app with scoring based on Peach Pellen’s tutorial here, so it wasn’t a top [...]

  19. I have not personally used Twitter yet as I am only recently a fan of it ;)

    Sometime in the near future I will investigate it and post a tutorial.

  20. Hi Peach,

    Do you know how to add scores to Twitter? It would be very helpful if you did a tutorial on that.

    Or does Twitter even support adding scores?


  21. Hello Hunnenkoeing – Sorry for the delay, I took yesterday off from the app stuff and Techority, so just getting to everyone now.

    The score will automatically stay for different levels using director; however if you want to reset it for each level I can help with that too.

    Email me if you need help with it, my email is on the sponsor page – but I think what you are asking is how to keep it there and counting up each level, which it should automatically do.

    Peach :)

  22. Hello peach,

    How can I add this to keep the score through different leveles?

    I am trying to understand it since 2 days and no matter what I try, it doesn’t work.

    Thanks if you can answer this. Maybe even by email? hunnenkoenig_at_chello_dot_at

  23. I saw that and retweeted it – good job!

    Hope to do more videos soon if I can, depends a bit on the heat – I don’t like to overwork my computer when the temperature is pushing 40C >.<‘ Damn weather!

  24. 11 points for each fish clicked… SCORE!
    thanks again for the tut!

  25. Hey there Bill, my FB buddy!

    Thrilled you are learning and I’m helping :D

  26. Thanks Peach! Another tool to add to my growing skills – I’ve learned so much from you already!

  27. I bet you will be able to make a great game before long :)

    Glad you liked the tut, hope it helps you when it’s “game time” ;)

    Peach :)

  28. Nice tut again, thanks a lot! I will dig it in depth tonight, specially the score.lua part, some mysteries in there still for me… but I’m progressing ;) and start to understand how this whole thing is working. A few more weeks exercising and I should be able to start something that looks like a game, lol.

  29. Hi William,

    Not a problem at all! I appreciate your kind words and am very glad that I’ve been helping you learn :)

    I am much happier with my life now that Corona is in it and I feel I owe it to Corona to help promote it and see it do well, even if I only play a tiny part – but I also owe it to other developers looking to find a tool that just works.

    I do my best to be helpful and nice and am certainly glad you think so :) Thank you.

    As to my sister, heh, we were just kids so there was a bit of teasing – nothing malicious really, but things like that can stick with you when you know you don’t sound like those around you, ya’know? ^-^; It’s all good, we’re all self conscious in some way – just some of us more than others.

    I hope to see more of you around!

    Peach :)

  30. Hi Peach,

    Thanks so much for the tutorial. Also thanks for the intro tutorial to Corona. I am also a GS user looking for something more powerful. I’ve also followed your post’s on the GS forum and have learned a great deal.

    Btw, your voice is beautiful. I love the accent. I think your sister is just jealous, lol.

    Your so helpful and nice.


  31. @JC – Haha, thanks so much :)

    @Tim – One of my sisters used to tease me about having a deep voice; it’s not too bad there in that regard because when I’m freakishly anxious it goes up a bit, haha, but it’s something that makes me a tad self conscious still. Thrilled it’s what you were looking for, let me know if you need help :)

    @Torrey – Biffy Beebe’s Icon Graphics Pack – Google that and it should be your first hit. It’s freaking awesome. My sales have been hugely improved by having good icons. You’ll see what I mean – makes icon making much easier, especially for people like me who can’t draw well ;)

    Peach :)

  32. Do you mind typing out the name of the graphics pack you mentioned?

  33. That was great! And exactly what I was looking for! How did you know?! ;-)
    Very cool…I can’t wait to try it.

    And lastly, but certainly not least, your voice was fine. Really. I agree with JC…why is it we don’t like our own voice?

  34. SCORE on the score tut! And your voice sounds fine – mine on the other hand, ugh! Why is it no-one likes their own voice? Thanks again I’m having a blast learning this way.

 Leave a Reply



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.