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:

 if lives == 0 then  
 local highScore = settings:getVar("score")  
 if score \>= highScore then  
 settings:setVar ("score", score)  
 end  
 director:changeScene("gameover")  
 end  

When I simulate the game over condition, it works fine but I have tested this on two separate android devices, one on 2.3.4 and the other on 2.2 and for both it simply freezes where it should be going to the gameover screen.

Any suggestions? Thank you. [import]uid: 50805 topic_id: 14057 reply_id: 314057[/import]

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.
[import]uid: 19626 topic_id: 14057 reply_id: 51757[/import]

try this:

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 [import]uid: 43961 topic_id: 14057 reply_id: 51758[/import]

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 [import]uid: 59140 topic_id: 14057 reply_id: 51759[/import]

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. [import]uid: 50805 topic_id: 14057 reply_id: 51770[/import]

Any more suggestions? I still have not found a solution… [import]uid: 50805 topic_id: 14057 reply_id: 53132[/import]

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. [import]uid: 67839 topic_id: 14057 reply_id: 53140[/import]

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? [import]uid: 50805 topic_id: 14057 reply_id: 53143[/import]