Jump to content




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


  • You cannot reply to this topic
7 replies to this topic

#1 Mackan90096

  • Signature Abuser
  • 518 posts
  • LocationIn my basement.

Posted 13 April 2013 - 04: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!

#2 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 13 April 2013 - 04:08 AM

No need of .. there, just like in line 13 (relative).

#3 Mackan90096

  • Signature Abuser
  • 518 posts
  • LocationIn my basement.

Posted 13 April 2013 - 04: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

#4 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 13 April 2013 - 04: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)


#5 Mackan90096

  • Signature Abuser
  • 518 posts
  • LocationIn my basement.

Posted 13 April 2013 - 04:18 AM

Oh, yeah.. Now its working! Thanks! :D

#6 Mackan90096

  • Signature Abuser
  • 518 posts
  • LocationIn my basement.

Posted 13 April 2013 - 04: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

#7 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 13 April 2013 - 04:42 AM

Again, that means fs couldn't open multicost. Are you sure you have a file called multicost?

#8 Mackan90096

  • Signature Abuser
  • 518 posts
  • LocationIn my basement.

Posted 13 April 2013 - 04:45 AM

whoops.. Didn't have that file..





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users