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!
0
(Question)Starting Out
Started by Slyth, Apr 20 2012 02:15 AM
4 replies to this topic
#1
Posted 20 April 2012 - 02:15 AM
#2
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
Type help turtle from the terminal or check out the apis section of the wiki for more turtle commands.
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
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
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 endYou 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
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