i = 0
repeat
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.up()
turtle.dig()
turtle.digUp()
turtle.forward()
turtle.digUp()
turtle.turnLeft()
i = i + 1
until i > 10
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Stair Building Help w/ Gravel
Started by xInDiGo, 09 January 2013 - 08:51 PMPosted 09 January 2013 - 09:51 PM
Hello, i'm working on a stair builder script. The one i have works great except when it comes into gravel. I'm aware there's a way to use a function to help w/ that but i'm not quite sure how to impliment it. Here's my current script. The script is to make the turtle build me a stair case back up, running it a few times till i reach the surface. Any tips or suggestions would be great. I've read through some other scripts and learned about functions but its all pretty new to me, so i'm looking for a little hands on help to get going.
Posted 09 January 2013 - 10:02 PM
firstly, [code][/code] instead of [quote][/quote] :)/>
now as for the code easiest is to do the following:
these will try to move the turtle, if it doesn't move it will dig… if you are running CC 1.4 you may also want it to attack a mob if it can't dig. example:
now as for the code easiest is to do the following:
while not turtle.forward() do
turtle.dig()
end
while not turtle.up() do
turtle.digUp()
end
these will try to move the turtle, if it doesn't move it will dig… if you are running CC 1.4 you may also want it to attack a mob if it can't dig. example:
if not turtle.dig() then
turtle.attack()
end
Posted 10 January 2013 - 07:43 AM
looks great, & pretty straight forward too! but how would i implement this? do i just put it in the loop? or after the loop? if i wanted to turn this into a function, would it look like this?
I'm still learning here but i'm not sure this would work as intended? i thought if i make this a function i can add it to the loop in place of the dig commands. correct me if i'm wrong here
function gravelCheck()
while not turtle.forward() do
turtle.dig()
if not turtle.dig() then
turtle.attack()
end
end
while not turtle.up() do
turtle.digUp()
end
end
I'm still learning here but i'm not sure this would work as intended? i thought if i make this a function i can add it to the loop in place of the dig commands. correct me if i'm wrong here
Posted 10 January 2013 - 07:55 AM
local setHeight = 10 -- Amount of blocks turtle should go up
local cHeight = 0 -- Current height of Turtle
while cHeight ~= 11 do
if not turtle.dig() then
turtle.attack() -- Attack forward if cant dig forward
turtle.dig()
turtle.forward()
else
turtle.forward() -- Move forward if succeeded
end
if not turtle.digUp() then
turtle.attackUp() -- Attack up if cant dig up
turtle.digUp()
turtle.up()
else
turtle.up()
end
cHeight = cHeight +1
end
This should work fine
EDIT: Fixed a thing
Posted 10 January 2013 - 08:29 AM
that one looks interesting. using the setHeight is useful that way i can determine how high it'll go a lot easier. From reading it, it doesn't look like it makes a spiral like the one i had used, and it looks like it doesn't make enough room for you to follow it up. but, if i wanted to make it a spiral, would i add
::edit::
just tried your default script and it did indeed do as i thought it would. it went in a straight line and didn't add enough room for me to follow it up, i also kept having to break the block above me. i've tweaked it to turn left and that seems to work great. But now i'm not sure where to add the turtle.digUp() before it moves forward while also gravel proofing it.
turtle.turnLeft()
after the "forward" in the if part or in the else part? by the way thanks for your guys help and patience while i work this out!::edit::
just tried your default script and it did indeed do as i thought it would. it went in a straight line and didn't add enough room for me to follow it up, i also kept having to break the block above me. i've tweaked it to turn left and that seems to work great. But now i'm not sure where to add the turtle.digUp() before it moves forward while also gravel proofing it.
Posted 10 January 2013 - 08:50 AM
local height = 10
function forward()
while not(turtle.forward()) do
turtle.dig()
turtle.attack()
sleep(0.25)
end
end
function up()
while not(turtle.up()) do
turtle.digUp()
turtle.attackUp()
end
end
function digUp()
while turtle.detectUp() do
turtle.digUp()
sleep(0.25)
end
end
for i = 1, height do
turtle.place()
up()
digUp()
forward()
turtle.turnRight()
end
That's my crack at this. Make sure to give him some cobble or something in slot 1 because he'll put it down if he comes across a spot that needs it.
Posted 10 January 2013 - 09:00 AM
That's my crack at this. Make sure to give him some cobble or something in slot 1 because he'll put it down if he comes across a spot that needs it.
so you're saying he'll place cobble if theres none where there should be? thats pretty smart! i'm going to run this through and see what i can do! i was able to tweak the other one and get it to work pretty well! but question how does the turtle know if it needs to place a block? i don't understand that part of the script.
Posted 10 January 2013 - 09:02 AM
That's my crack at this. Make sure to give him some cobble or something in slot 1 because he'll put it down if he comes across a spot that needs it.
so you're saying he'll place cobble if theres none where there should be? thats pretty smart! i'm going to run this through and see what i can do! i was able to tweak the other one and get it to work pretty well! but question how does the turtle know if it needs to place a block? i don't understand that part of the script.
he doesn't really know. he just tries to place it and if there is already a block there he will just fail and move on.
Posted 10 January 2013 - 09:37 AM
he doesn't really know. he just tries to place it and if there is already a block there he will just fail and move on.
thats great! this worked perfect! i'm gonna play around with the code and make sure i understand why it works! thanks again for all your help! but believe me, this won't be my last post :P/>
Posted 10 January 2013 - 09:38 AM
he doesn't really know. he just tries to place it and if there is already a block there he will just fail and move on.
thats great! this worked perfect! i'm gonna play around with the code and make sure i understand why it works! thanks again for all your help! but believe me, this won't be my last post :P/>
glad I could help :)/>