Works in simulator, not on phone

Hello,

I'm trying to make a game using corona and I've run into a minor problem that I'm not sure how to fix.

When my game reaches the end (lives = 0) it will use the settings class to see if their current score is higher than the highscore and if it is, it will store it. Then I call the director class to take the user to the game over screen. The code is as follows:

1
2
3
4
5
6
7
      if lives == 0 then
        local highScore = settings:getVar("score")
        if score >= highScore then
          settings:setVar ("score", score)
        end
        director:changeScene("gameover")
      end

My only thought would be that your code to save the scores is crashing perhaps something different in the sandbox. Like your score file already existing on the simulator, but it doesn't exist on the app, so when it tries to read the score its crashing.

I had similar issues as I was building my settings/saving/reading code.

try this:

1
2
3
4
5
6
7
8
9
      if lives == 0 then
        local highScore = settings:getVar("score")
        highScore = tonumber(highScore)
        score = tonumber(score)
        if score >= highScore then
          settings:setVar ("score", score)
        end
        director:changeScene("gameover")
      end

I'm not totally sure about the code but don't forget to open the Corona Terminal before the sim. It will show any errors and might give some insight as to why it's not working right. I've had that happen where it was working on the simulator then I put it on my iPod and found it didn't work and later found an error in the terminal.

Hope that helps

Thanks for all the suggestions. I'm trying brettmaddern's suggestion now and Dannylego, there were no outputs to the terminal indicating any errors unfortunately.

robmiracle, I think I understand what you're saying but how would I go about fixing that?

Thanks again.

Edit: The tonumber advice did not work.

Any more suggestions? I still have not found a solution...

I would comment out the line where you save the score, and then see if it still crashes on the device.

If it doesn't, that would at least let you know that the problem is with that one line.

Well I commented out everything with the high score setting and it still freezes. Must be an issue with director or my gameover file then?

views:1307 update:2011/9/26 15:43:22
corona forums © 2003-2011