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

[Program] Bad argument: double expected

Started by Crowbar Sr, 19 October 2012 - 06:55 PM
Crowbar Sr #1
Posted 19 October 2012 - 08:55 PM
Hey there,
I'm trying to learn CC and I've run into a pickle.

I've modified the tutorial code on the wiki but I get this error.
When I enter the password wrong, the code works fine and provides the bottom redstone pulse, but when it's correct the redstone signal remains and this error appears:

bios:25: bad argument: double expected, got nill

Here's the code I've used

local side = "back"
local password = "hello"
local opentime = 5
local bottom = "bottom"
while true do
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input = read("*")
  term.clear()
  term.setCursorPos(1,1)
  print("Password correct!")
  sleep(1)
  rs.setOutput(side,true)
  sleep(opentime)
  rs.setOutput(side,false)
else
  print("Password incorrect!")
  sleep(1)
  rs.setOutput(bottom,true)
  sleep(1)
  rs.setOutput(bottom,false)
  sleep(1)
end
end

Any help would be appreciated, thank you!
faubiguy #2
Posted 19 October 2012 - 09:28 PM
This code doesn't run at all. I think you're missing an if statement to check if the password is correct. The issue you posted would be caused by opentime not being defined, however it is defined at the top, and after running the program with "if input == password" right after "local input = read("*")", it ran correctly.
remiX #3
Posted 19 October 2012 - 10:49 PM
Yeah, you're missing an if statement to check if the password is correct :P/>/>


local side = "back"
local password = "hello"
local opentime = 5
local bottom = "bottom"
while true do
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input = read("*")
if input == password then
  term.clear()
  term.setCursorPos(1,1)
  print("Password correct!")
  sleep(1)
  rs.setOutput(side,true)
  sleep(opentime)
  rs.setOutput(side,false)
else
  print("Password incorrect!")
  sleep(1)
  rs.setOutput(bottom,true)
  sleep(1)
  rs.setOutput(bottom,false)
  sleep(1)
end
end