Lua saving to file -


i'm working on small project in lua , having problem saving score disk.

my code this, , print message.

function savehighscore(score)     print("high score: "..tostring(score))     local file = io.open("high_score.txt",'w')     file:write(tostring(score))     file:close() end 

anyone out there can help?

sure, have solved faster if followed first 2 comment's advices. here how it's done "in case else stuck same problem , came across this":

function savehighscore(score)     print("high score: "..tostring(score))     local file,err = io.open("high_score.txt",'w')     if file         file:write(tostring(score))         file:close()     else         print("error:", err) -- not hard?     end end 

http://www.lua.org/manual/5.3/manual.html#pdf-io.open:

io.open (filename [, mode])

this function opens file, in mode specified in string mode. returns new file handle, or, in case of errors, nil plus error message.


Comments

Popular posts from this blog

c# - Where does the .ToList() go in LINQ query result -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -