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

Can't get elseif statement working for my path finder

Started by goblim, 07 June 2015 - 01:04 AM
goblim #1
Posted 07 June 2015 - 03:04 AM

while true do
p1,p2 = turtle.inspectDown()
if p1 == true then
if p2.name == "minecraft:stone" then
turtle.forward()
elseif p2.name ~= "minecraft:stone" then
turtle.turnRight()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.forward()
else
turtle.turnRight()
turtle.turnRight()
turtle.forward()
turtle.forward()
end
end
end


I'm sure it is a quick fix but I don't have the knowledge to do it. I want the turtle to continue forward until it is no longer on stone. At that point it turns right twice moves forward then turns right. It then checks the next block it runs into. it does all this correctly. Where the problem is when it doesn't find stone under it after the first try. I cannot get the second check ( the last else statement) to run. Any help?
Lyqyd #2
Posted 07 June 2015 - 03:35 AM
It's either going to be minecraft:stone or it isn't, there isn't a third option. How could it possibly not be one of the first two options?
Bomb Bloke #3
Posted 07 June 2015 - 04:25 AM
I cannot get the second check ( the last else statement) to run. Any help?

Under what exact circumstances do you want it to run?
goblim #4
Posted 07 June 2015 - 07:23 PM
When the turtle leaves the stone the first time I want it to run the first else statement. If that finds no stone I want the turtle to run the last else statement. It probably should not be a else statement running this but that is what I thought of.
Edited on 07 June 2015 - 05:27 PM
goblim #5
Posted 07 June 2015 - 07:45 PM
I have now found a fix thanks for pointing that flaw out

while true do
p1,p2 = turtle.inspectDown()
if p1 == true then
if p2.name == "minecraft:stone" then
turtle.forward()
elseif p2.name ~= "minecraft:stone" then
turtle.turnRight()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.forward()
p1,p2 = turtle.inspectDown()
if p2.name == "minecraft:stone" then
p1,p2 = turtle.inspectDown()
else
turtle.turnRight()
turtle.turnRight()
turtle.forward()
turtle.forward()
end
end
end
end