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

Simple stairs!

Started by Noodle, 28 February 2012 - 11:11 PM
Noodle #1
Posted 29 February 2012 - 12:11 AM
Here is the stairs code:


-- Written By: Noodle
-- Any suggestions? Msg me!
n = 1

while turtle.detect() == false do
turtle.forward()
if turtle.down() == false then
os.reboot()
end
turtle.placeDown()
if turtle.detect() == true then
turtle.turnRight()
turtle.placeDown()
   end
if turtle.getItemCount(n) <1 then
n = n + 1
turtle.select(n)
   end
end

Finished &amp; Tested!

How to add
——————————
1. Copy code
2. Paste in notepad
3. save to %appdata% – .minecraft/mods/computercraft/lua/rom/programs
4. Name it Stair or whatever you will remember it by
5. If it automatically puts .txt or any other extension, get rid of it.

How to use
——————————
When turtle is done excavating collect all materials and put in whatever material you want for stairs.
Then type whatever YOU NAMED IT AS.
ThePH #2
Posted 29 February 2012 - 12:55 AM
use turtle.getItemCount(n) and turtle.select(n) ^_^/>/>
Noodle #3
Posted 29 February 2012 - 01:12 AM
Code thing is messed… Added the moving slots thx to ThePH for helping.
ThePH #4
Posted 29 February 2012 - 08:12 AM
ill try to see for the first thing later cause im on a phone.
Chub1337 #5
Posted 29 February 2012 - 09:35 AM
1. When it hits the ground it doesn't stop moving.

That is because it only checks if there is space to move forward, and if that is true, it'll move forward and down and place block, but because it is at the ground already, it'll only move forward (it can't move down or place blocks since there is ground underneath the turtlebot).

To fix the problem, add a check for moving down aswell
 turtle.detectDown()
, I'm sure you'll figure it out :o/>/> (If not, feel free to ask)

-Chub1337
Noodle #6
Posted 04 March 2012 - 02:36 AM
Tried using
turtle.detectDown()
it detects the stairs, only way to change is if I make a completely new program.
Espen #7
Posted 04 March 2012 - 03:00 AM
Tried using
turtle.detectDown()
it detects the stairs, only way to change is if I make a completely new program.
Instead of (only) trying to detect if there's something below the turtle, try to check if the movement of the turtle was successful.
Every movement-function of the turtle returns a boolean value: true if it moved successfully, false if it didn't.
So if you do sth. like this…
local hasMoved = turtle.down()
… then hasMoved would contain either true or false.
Depending on the value you can then react:

if not hasMoved then
  -- Do something if the turtle tried to move downwards but couldn't/didn't.
end
rerere284 #8
Posted 04 March 2012 - 11:17 PM
I think turtles automatically go through their inventory…

You can solve your problems by each time your turtle tries to move anywhere, it looks to see if something is there, and if there is, it digs it up.
Also, I did not know that the movement functions did that. :unsure:/>/>



--functions

function forward() --if something is in front of it, dig it away.
if turtle.detect() then
turtle.dig()
end
turtle.forward() --if something was there or not, it goes forward afterwards.
end

function down() --same thing here, but downwards.
if turtle.detectDown() then
turtle.digDown()
end
turtle.down()
end

function place() --Here, it only tries to place a block if there is not already one there.
if not turtle.detectDown() then
turtle.placeDown()
end

--end functions

print("How deep?")
ammount = read() --read() is a function which returns text you inputted. You can finish inputting by pressing enter.
for i=1, ammount do --it then goes into a for loop, which is a loop where it does something for the specified amount of times. 

down()
down()
place()
turtle.up()
forward()

end


This would have problems if it ran into gravel or sand though, and does not return to the surface. (not that hard to make it return to the surface though, just add another for loop)
Noodle #9
Posted 08 March 2012 - 02:56 AM
I see your how deep, but I can recode my first program. Not hard, thanks to Espen. Sorry couldn't reply or make new because I was on vacation.
Noodle #10
Posted 08 March 2012 - 03:23 AM
Finished! Code tested and works!
Noodle #11
Posted 08 March 2012 - 03:49 AM
I think turtles automatically go through their inventory… You can solve your problems by each time your turtle tries to move anywhere, it looks to see if something is there, and if there is, it digs it up. Also, I did not know that the movement functions did that. :mellow:/>/>
 --functions function forward() --if something is in front of it, dig it away. if turtle.detect() then turtle.dig() end turtle.forward() --if something was there or not, it goes forward afterwards. end function down() --same thing here, but downwards. if turtle.detectDown() then turtle.digDown() end turtle.down() end function place() --Here, it only tries to place a block if there is not already one there. if not turtle.detectDown() then turtle.placeDown() end --end functions print("How deep?") ammount = read() --read() is a function which returns text you inputted. You can finish inputting by pressing enter. for i=1, ammount do --it then goes into a for loop, which is a loop where it does something for the specified amount of times. down() down() place() turtle.up() forward() end 
This would have problems if it ran into gravel or sand though, and does not return to the surface. (not that hard to make it return to the surface though, just add another for loop)

Your program is useful for non-dug up quarries. I'm talking about quarries that are finished and you want stairs to go down them.