This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Mackan90096's profile picture

[Error] [string "gemminer"]:61: unexpected symbol

Started by Mackan90096, 13 April 2013 - 03:00 AM
Mackan90096 #1
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!
LBPHacker #2
Posted 13 April 2013 - 05:08 AM
No need of .. there, just like in line 13 (relative).
Mackan90096 #3
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
LBPHacker #4
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)
Mackan90096 #5
Posted 13 April 2013 - 05:18 AM
Oh, yeah.. Now its working! Thanks! :D/>
Mackan90096 #6
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
LBPHacker #7
Posted 13 April 2013 - 05:42 AM
Again, that means fs couldn't open multicost. Are you sure you have a file called multicost?
Mackan90096 #8
Posted 13 April 2013 - 05:45 AM
whoops.. Didn't have that file..