Hello there,
I am new to Corona SDK and I am having this problem while testing my build on the simulator. I am trying to
use “score.lua” module from https://coronalabs.com/blog/2013/12/10/tutorial-howtosavescores/ to save
and update scores.
Only modification I have made to the code are :
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 = 4 M.filename = "scorefile.txt" local prefix = "" 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 -- AND THE FOLLOWING function M.set( value ) M.score = value M.text = tostring( M.score ) end
set and get score modules are working fine. However, when I try to save or load, I get these errors respectively,
Error: could not read nil
Error: could not read scores form nil
Is “scorefile.txt” a file I should create myself? If so where should it be? I have placed
“scorefile.txt” in the same directory where main.lua is. I have also placed one in the directory
File > Project Sandbox > Documents. However, it is still unable to read/write score.
Any help/suggestions would be greatly appreciated.
Thanks.