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

[Error] File exists + Attempt to call string

Started by MostlyClueless, 30 June 2012 - 11:01 PM
MostlyClueless #1
Posted 01 July 2012 - 01:01 AM
I'm having some issues with my password script, I've looked through the code so many times that these two errors are probably in plain sight and I just can't spot them.

The Script

Here are the two problem areas:

154:attempt to call string

The error is found here. The password can be changed once successfully but trying to do it again results in an error.



function settingsmenu1()
cls()
print("Settings Menu")
print(" ")
print(" [ Change Password ] ")
print("   Change Username   ")
print(" ")
print("   Return to Tools Menu  ")
local event, param1 = os.pullEvent() 
if param1 == 200 then 
settingsmenu3()
elseif param1 == 208 then
settingsmenu2()
elseif param1 == 28 then
changepass() -- after calling the changepass function once, trying to call it again yields "154: attempt to call string
end
end

Here is the changepass function:



function changepass()
cls()
write("Enter a new password here: ")
changepass = read()
fs.delete("appsupport/passwordlock/users/"..globaluser.."/password.txt")
passchange = fs.open("appsupport/passwordlock/users/"..globaluser.."/password.txt", "w")
passchange.writeLine(changepass)
passchange.close()
print("Password changed to '"..changepass.."'.")
sleep(2)
settingsmenu1()
end

217: File Exists







function changeuser()
cls()
write("Enter a new username here: ")
changeuser = read()
print(" ")
write("Changing some files.")
fs.makeDir("appsupport/passwordlock/temppass")
sleep(.3)
write(".")
fs.copy("appsupport/passwordlock/users/"..globaluser.."/password.txt", "appsupport/passwordlock/temppass") -- Error occurs here.
sleep(.3)
write(".")
fs.delete("appsupport/passwordlock/users/"..globaluser)
sleep(.3)
write(".")
fs.makeDir("appsupport/passwordlock/user/"..changeuser)
sleep(.3)
write(".")
fs.copy("appsupport/passwordlock/temppass/password.txt", "appsupport/passwordlock/users/"..globaluser.."/password.txt")
if admin == true then
fs.delete("appsupport/passwordlock/admins/"..globaluser)
fs.makeDir("appsupport/passwordlock/admins/"..changeuser)
end
globaluser = changeuser
print("Username changed to '"..changeuser.."'.")
sleep(2)
settingsmenu2()
end


Luanub #2
Posted 01 July 2012 - 01:16 AM
For the first probelm:
You're using changepass and changeuser both as function's and variable's. Rename either the var or the function.

Since lua is case sensitive you can do changePass and changepass or any other variation with different case letters.

For the second:
Change

fs.copy("appsupport/passwordlock/users/"..globaluser.."/password.txt", "appsupport/passwordlock/temppass")

to

fs.copy("appsupport/passwordlock/users/"..globaluser.."/password.txt", "appsupport/passwordlock/temppass/password.txt")
fs needs the absolute path.
MostlyClueless #3
Posted 01 July 2012 - 01:26 AM
For the first probelm:
You're using changepass and changeuser both as function's and variable's. Rename either the var or the function.

Since lua is case sensitive you can do changePass and changepass or any other variation with different case letters.

For the second:
Change

fs.copy("appsupport/passwordlock/users/"..globaluser.."/password.txt", "appsupport/passwordlock/temppass")

to

fs.copy("appsupport/passwordlock/users/"..globaluser.."/password.txt", "appsupport/passwordlock/temppass/password.txt")
fs needs the absolute path.

Thanks for the quick response! The first issue was resolved quickly with a few changes, however my second issue is now calling an error further down! Sorry for my rather extreme noobiness and thanks again for your time. I fixed my issue!