25 posts
Location
Melbourne (AU)
Posted 16 July 2015 - 06:07 AM
Hello, I am trying to make a program that builds me a giant rail.
I want it to automatically place down powered rail every ten blocks.
Here is my code:
local X
X = 10
while true do
if turtleedu.inspect() ~= "minecraft:air" then
turtle.dig()
turtle.forward()
X = X - 1
end
if X > 0 then
turtle.select( 1 )
turtle.forward()
turtle.placeDown()
end
if X == 0 then
turtle.select( 2 )
turtle.placeDown()
X = 10
end
end
VISUAL
ComputerCraftEdu:variable X
ComputerCraftEdu:equalTo
ComputerCraftEdu:number 10
957 posts
Location
Web Development
Posted 16 July 2015 - 06:48 AM
if turtleedu.inspect() ~= "minecraft:air" then
turtle.dig()
turtle.forward()
X = X - 1
end
You can do this instead:
while not turtle.forward() do
turtle.dig()
end
It takes care of sand / gravel.
Also, read this carefully:
while true do
if turtleedu.inspect() ~= "minecraft:air" then
turtle.dig()
turtle.forward()
X = X - 1
end
...
end
If it finds just air in front of the turtle, it won't decrease X!
Just put that after the if-statement (or the while statement if you use my suggestion)
Are you having any other problems?
Edited on 16 July 2015 - 04:51 AM
7083 posts
Location
Tasmania (AU)
Posted 16 July 2015 - 06:49 AM
Part of the problem here is that you're only decrementing X if there's something other than air in front of the turtle.
Try it like this:
local X = 10
while true do
-- Until an attempt to go forward succeeds, wave the pickaxe at blocks/mobs:
while not turtle.forward() do
turtle.dig()
turtle.attack()
end
-- Just in case there's something blocking our rail:
if turtle.detectDown() then turtle.digDown() end
-- Change X and choose our rail:
if X > 0 then
turtle.select( 1 )
X = X - 1
else
turtle.select( 2 )
X = 10
end
-- Place the selected rail:
turtle.placeDown()
end
Which in the visual editor would look like this:
You'd still need to think about how to ensure that there's a block to place the rails on, though!
25 posts
Location
Melbourne (AU)
Posted 16 July 2015 - 07:04 AM
Thankyou guys, I've taken in your feedback and gotten the program to work :)/>.
Also to your last statement BombBloke, I needed this information to also create the second program for a second turtle that was placing down blocks for the rail to go onto
81 posts
Posted 16 July 2015 - 07:19 PM
Thankyou guys, I've taken in your feedback and gotten the program to work :)/>/>.
Also to your last statement BombBloke, I needed this information to also create the second program for a second turtle that was placing down blocks for the rail to go onto
You may wish to try having your turtle go backwards, that way it can both place the rails and check for a stable floor. When it runs into something you can turn it around to break the blocks until it can move forward again, at which point you make it go backwards and placing rails again.
Alternatively you could also make it go up the hills it could run into