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

(Question)Starting Out

Started by Slyth, 20 April 2012 - 01:15 AM
Slyth #1
Posted 20 April 2012 - 03:15 AM
Ok, so I just started computercraft and i have done real simple things such as "Hello World". I would like to know how to create a turtle program to build a simple house, 5x5 and 4 blocks tall. Also how do i repeat like 3 lines of code in one line; eg, instead of
turtle.placeDown()
turtle.placeDown()
turtle.placeDown()
into one line?
Thanks!
Luanub #2
Posted 20 April 2012 - 03:24 AM
You got the general idea.

Use turtle.select(slotnumber) to select the inventory slot that has the building materials in it.

Then use turtle.place() or one of the other place commands to place the block.

To repeat a function say 3 times you will need to do a for loop

Example: – will move the turtle forward 3 spaces

for x=1, 3 do
turtle.forward()
end

Type help turtle from the terminal or check out the apis section of the wiki for more turtle commands.
Teraminer #3
Posted 20 April 2012 - 10:06 AM
Go here http://computercraft.info/wiki/index.php?title=Turtle_%28API%29 it has the list of all the functions the turtle can use.
EatenAlive3 #4
Posted 22 April 2012 - 01:35 AM
If you're making a turtle program, one of the first things I would recommend is to automate the movement functions. For example, this code would automate the turtle.forward() function:

function forward(spaces)
  if not spaces then spaces = 1 end
  local state = true
  while state and spaces < 0 do
    state = turtle.forward()
    spaces = spaces - 1
  end
  return state
end
You could also download or create a turtle API to do these things outside of one program. With streamlined functions, all you will ever need to do is one function rather than a for loop.
Slyth #5
Posted 22 April 2012 - 02:45 PM
Ok awesome thanks guys. I think I'm going to start out with a simple 1 block tower. From there maybe a house! Again thanks.