695 posts
Location
In my basement.
Posted 13 April 2013 - 05:00 AM
I'm trying to make a save/load thing for my game but i get an error:
[string "gemminer"]:61: unexpected symbol
Relevant code:
Line 61 is in this case line 9.
function save()
term.clear()
term.setCursorPos(1,1)
write("Name: ")
usrName = read()
fs.makeDir("saves")
if not fs.exists("saves/"..usrName.."/money") then
file = fs.open("saves/"..usrName.."/money", "w")
file.writeLine(..money)
file.close()
if not fs.exists("saves/"..usrName.."/multiplier") then
file2 = fs.open("saves/"..usrName.."/multiplier", "w")
file2.writeLine(..multi)
file2.close()
sleep(0.5)
term.clear()
term.setCursorPos(1,1)
print("Registered!")
sleep(0.5)
term.clear()
game()
end
end
end
Thankful for help!
758 posts
Location
Budapest, Hungary
Posted 13 April 2013 - 05:08 AM
No need of .. there, just like in line 13 (relative).
695 posts
Location
In my basement.
Posted 13 April 2013 - 05:13 AM
New code:
function save()
term.clear()
term.setCursorPos(1,1)
write("Name: ")
usrName = read()
fs.makeDir("saves")
if not fs.exists("saves/"..usrName.."/money") then
file = fs.open("saves/"..usrName.."/money", "w")
file.writeLine(money)
file.close()
if not fs.exists("saves/"..usrName.."/multiplier") then
file2 = fs.open("saves/"..usrName.."/multiplier", "w")
file2.writeLine(multi)
file2.close()
sleep(0.5)
term.clear()
term.setCursorPos(1,1)
print("Registered!")
sleep(0.5)
term.clear()
game()
end
end
end
New error:
gemminer:61: attempt to index ? (a nil value)
Line 61 is in this case too line 9
758 posts
Location
Budapest, Hungary
Posted 13 April 2013 - 05:15 AM
Insert this before line 61:
print(file)
I think it'll print "nil". In that case, fs couldn't open the file. Check the path. You might want to create a new directory for the user:
fs.makeDir("saves/" .. usrName)
695 posts
Location
In my basement.
Posted 13 April 2013 - 05:18 AM
Oh, yeah.. Now its working! Thanks! :D/>
695 posts
Location
In my basement.
Posted 13 April 2013 - 05:35 AM
But my loading isn't working. :(/>
Code:
function load()
term.clear()
term.setCursorPos(1,1)
write("Name: ")
usrName = read()
if not fs.exists("saves/"..usrName) then
print("Not a valid name!")
sleep(1)
main()
elseif fs.exists("saves/"..usrName) then
term.clear()
term.setCursorPos(1,1)
print("Loading")
file = fs.open("saves/"..usrName.."/money", "r")
money = file.readLine()
file.close()
file2 = fs.open("saves/"..usrName.."/multiplier", "r")
multi = file2.readLine()
file2.close()
file3 = fs.open("saves/"..usrName.."/multicost", "r")
multiCost = file3.readLine()
file3.close()
sleep(1)
term.clear()
print("Loaded")
game()
end
end
gemminer:70:
attempt to index ? (a nil value)line 70 is in this case line 21
758 posts
Location
Budapest, Hungary
Posted 13 April 2013 - 05:42 AM
Again, that means fs couldn't open multicost. Are you sure you have a file called multicost?
695 posts
Location
In my basement.
Posted 13 April 2013 - 05:45 AM
whoops.. Didn't have that file..