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

[Lua] [Error] I'm getting an error and I have no idea what's causing it.

Started by oneupe1even, 17 December 2012 - 02:05 PM
oneupe1even #1
Posted 17 December 2012 - 03:05 PM
I am creating an advanced password protected door to test my Lua skills, but I'm getting an error and I don't know what's causing it. Here is my code:


function clear()
term.setCursorPos(1,1)
term.clear()
end
clear()
local password -- Defines a string containing the password to be used in the door.
local openTime -- Defines an integer to be used to set how long the door will be open.
local availibleSides = {"top, ", "bottom, ", "left, ", "right, ", "front, ", "back", "\n"}
local redstoneOutputSide -- Defines a string to be used to set the output of a redstone signal.
local userInput -- Defines a string to be used with read().
print("Please define your desired password:") -- Prints the string defined by the quote marks.
password = read() --Setting the password string as whatever the user inputs.
clear() -- Calling the function I made.
print("Please define the amount of time the redstone pulse will be activated:") -- Already explained.
openTime = read() -- Already explained.
clear() -- Already explained.
print("On which side will the redstone be activated?") -- Already explained.
print("Availbe sides are:") -- Already explained.
for i = 1, 7 do
write(availibleSides[i])
end
print("Please define a side:")
redstoneOutputSide = read()
clear()
while true do
clear()
write("Please input password: ")
userInput = read("*")
if userInput == password then
  clear()
  print("Password is correct! Opening door...")
  rs.setOutput(redstoneOutputSide, true)
  sleep(openTime)
  rs.setOutput(redstoneOutputSide, false)
else
  print("Password is incorrect! Rebooting program...")
  sleep(2)
end
end

Here is a pastie link for those who want it: http://pastie.org/5541051

It works up until the point to where it asks for the password, if you enter it right you get this in the terminal:


Password is correct! Opening door...
bios:133: Expected number

No idea what's causing this, any help would be appreciated. :)/>
theoriginalbit #2
Posted 17 December 2012 - 03:12 PM
when you do this line

openTime = read()

if stores a string. change to this



openTime = tonumber(read())

should fix the problem :)/>

hope this helps :)/>
oneupe1even #3
Posted 17 December 2012 - 03:33 PM
when you do this line

openTime = read()

if stores a string. change to this



openTime = tonumber(read())

should fix the problem :)/>

hope this helps :)/>

Worked great, thanks!
theoriginalbit #4
Posted 17 December 2012 - 03:34 PM
no problems :)/>