Jump to content




(Question)Starting Out


4 replies to this topic

#1 Slyth

  • New Members
  • 16 posts

Posted 20 April 2012 - 02: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!

#2 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 20 April 2012 - 02: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.

#3 Teraminer

  • New Members
  • 175 posts
  • LocationDon't look behind you..

Posted 20 April 2012 - 09:06 AM

Go here http://computercraft...urtle_%28API%29 it has the list of all the functions the turtle can use.

#4 EatenAlive3

  • New Members
  • 53 posts

Posted 22 April 2012 - 12: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.

#5 Slyth

  • New Members
  • 16 posts

Posted 22 April 2012 - 01: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users