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

[SOLVED]Then Expected

Started by Rangicus, 04 September 2012 - 02:45 AM
Rangicus #1
Posted 04 September 2012 - 04:45 AM
I am making a program that creates a downward staircase this is a what I have so far

function check()
print("Am I facing the correct direction? true/false")
check = io.read()
if check == false then
  turtle.turnLeft()
  check()
else
  stair()
end
end
function stair()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.down()
turtle.detectDown()
end
I have two things
1: It always returns this error

:5: 'then' expected
2: I don't know how to stuff booleans from turtle.detect() into a variable
SOLVED
Edited on 09 September 2012 - 09:02 PM
Kingdaro #2
Posted 04 September 2012 - 05:14 AM
Technically, there shouldn't be any error here, but I do see one problem.


if check == false then

io.read() returns a string, and when checking it against a boolean, it'll always return false.


if check == 'false' then

^This would be the correct way of accepting input.

As for your second problem, you can drop bools into a variable by simply doing "abool = turtle.detect()"
ben657 #3
Posted 05 September 2012 - 02:02 PM
Don't know if you still need help with this, but your variable "check" and the function "check" have the same name, which is probably confusing Lua, try renaming one of them throughout the code :D/>/>
sjele #4
Posted 06 September 2012 - 06:52 PM
Don't know if you still need help with this, but your variable "check" and the function "check" have the same name, which is probably confusing Lua, try renaming one of them throughout the code :D/>/>


function test()
print("test")
end

test = testing – This line removes the function. Works fine if this is removed

print(test)
test()

So this will produce the error attemting to call nil on line 7 : test()

You should maybe rename one of them, if you do use check = something and call function after that it breaks