Jump to content




[SOLVED]Then Expected


  • You cannot reply to this topic
3 replies to this topic

#1 dw28394

  • Members
  • 84 posts

Posted 04 September 2012 - 03: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 by Rangemuldee, 09 September 2012 - 10:02 PM.


#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 04 September 2012 - 04: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()"

#3 ben657

  • Members
  • 65 posts

Posted 05 September 2012 - 01: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/>

#4 sjele

  • Members
  • 334 posts
  • LocationSomewhere on the planet called earth

Posted 06 September 2012 - 05:52 PM

View Postben657, on 05 September 2012 - 01:02 PM, said:

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users