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

Help with attempt to index nil errors

Started by dadragon84, 28 June 2013 - 04:32 AM
dadragon84 #1
Posted 28 June 2013 - 06:32 AM
I need help I have several scripts saying the same thing

login:10: attempt to index ? (a nil value)

how can I get this fixed

Spoilerterm.clear()
term.setCursorPos(20,3)
print("Login System")
term.setCursorPos(1,6)

term.setCursorPos(10,8)
print("Name: ")
term.setCursorPos(10,10)
print("Password: ")
term.setCursorPos(20,8)
name = read()
term.setCursorPos(20,10)
pass = read()

login = ""



dbp = io.open("DB/DBlog/" ..name)
if dbp
then
corpass = dbp:read()
dbp:close()
if pass == corpass
then
login = "good"
end
end

sleep(1)
term.clear()
term.setCursorPos(20,3)
print("Login System")
term.setCursorPos(1,6)
if login == "good"
then
print("login accepted" )
end

if login == "good"
then
DBcn = io.open("DB/DBcur/name", "w")
DBcn:write(name)
DBcn:close()

DBl = io.open("DB/DBlvl/"..name, "r")
lvl = DBl:read()
DBl:close()

DBcl = io.open("DB/DBcur/level", "w")
DBcl:write(lvl)
DBcl:close()
end

sleep(1)

Create:28: attempt to index ? (a nil value)
Spoilerterm.clear()
term.setCursorPos(18,3)
print("Account Creation")

term.setCursorPos(10,8)
write("Name: ")
term.setCursorPos(10,10)
write("Password: ")
term.setCursorPos(20,8)
name = read()
term.setCursorPos(20,10)
pass = read()

term.setCursorPos(5,12)

dbp = io.open("DB/DBlog/"..name, "r")
if dbp
then
dbp:close()
print("Username already exists")
sleep(1)
term.setCursorPos(5,13)
print("Shutting down now")
sleep(1.5)
os.shutdown()
else
dbp = io.open("DB/DBlog/"..name, "w")
dbp:write(pass)
dbp: close()

dbl = io.open("DB/DBlvl/"..name, "w")
dbl:write("1")
dbl:close()

print("New account created")
sleep(1)
term.setCursorPos(5,13)
print("ending session")
sleep(1.5)
os.shutdown()
end

any help is appreciated
Lyqyd #2
Posted 28 June 2013 - 12:44 PM
Split into new topic.

The stated errors don't match with the errors the code would actually throw if you ran it. If you re-typed it here, please re-check it, character for character, to ensure that it is a complete match for what is in the actual computer.

Also, please make sure that all the folders you're using (/DB, /DB/DBlog, etc.) actually exist.