App on device is different than app on simulator!

Here you are:

Apr 5 14:11:00 iPhone-di-Lorenzo gameInDev2[2507] \<Warning\>: 21 Apr 5 14:11:00 iPhone-di-Lorenzo gameInDev2[2507] \<Warning\>: Could not read scores from scorefile.txt . Apr 5 14:11:00 iPhone-di-Lorenzo gameInDev2[2507] \<Warning\>: nil Apr 5 14:11:00 iPhone-di-Lorenzo gameInDev2[2507] \<Warning\>: Runtime error /Users/developer/Desktop/gameInDev2/game.lua:260: attempt to compare number with nil stack traceback: [C]: ? /Users/developer/Desktop/gameInDev2/game.lua:260: in function \</Users/developer/Desktop/gameInDev2/game.lua:238\> ?: in function \<?:218\> Apr 5 14:11:00 iPhone-di-Lorenzo gameInDev2[2507] \<Warning\>: Runtime error stack traceback: [C]: ? /Users/developer/Desktop/gameInDev2/game.lua:260: in function \</Users/developer/Desktop/gameInDev2/game.lua:238\> ?: in function \<?:218\>

as you can see it says “Could not read scores from scorefile.txt”. I’ve checked out the project sandbox and I figured out that it can write on that file, it can’t just read it

And then there’s “attempt to compare number with nil” at line 260. which is 

if (a \< b) then

The error is likely in the score module.  I suspect that’s the source of the problem.  Can you post your score.lua?

I think that too, anyway here it is

-- Score Module -- local M = {} -- create our local M = {} M.score = 0 function M.init( options ) local customOptions = options or {} local opt = {} opt.fontSize = customOptions.fontSize or 24 opt.font = customOptions.font or native.systemFontBold opt.x = customOptions.x or display.contentCenterX opt.y = customOptions.y or opt.fontSize \* 0.5 opt.maxDigits = customOptions.maxDigits or 6 opt.leadingZeros = customOptions.leadingZeros or false M.filename = customOptions.filename or "scorefile.txt" local prefix = "" if opt.leadingZeros then prefix = "0" end M.format = "%" .. prefix .. opt.maxDigits .. "d" M.scoreText = display.newText(string.format(M.format, 0), opt.x, opt.y, opt.font, opt.fontSize) return M.scoreText end function M.set( value ) M.score = value M.scoreText.text = string.format(M.format, M.score) end function M.get() return M.score end function M.add( amount ) M.score = M.score + amount M.scoreText.text = string.format(M.format, M.score) end function M.save() local path = system.pathForFile( M.filename, system.DocumentsDirectory) local file = io.open(path, "w") if file then local contents = tostring( M.score ) file:write( contents ) io.close( file ) return true else print("Error: could not read ", M.filename, ".") return false end end function M.load() local path = system.pathForFile( M.filename, system.DocumentsDirectory) local contents = "" local file = io.open( path, "r" ) if file then -- read all contents of file into a string local contents = file:read( "\*a" ) local score = tonumber(contents); io.close( file ) return score end print("Could not read scores from ", M.filename, ".") return nil end return M

If you have never called score.save(), it won’t have a save file to read from.  I suspect that when you call score.load() it’s returning nil and you are trying to then compare your score to nil giving you that error.

What I would do is I would do:

local b = score.load()

if b == nil then

    b = 0

end

That way it will cover our base for not having has a previously saved score.

Great it works!! Thanks a lot!