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

Simple 11x11 House with Skylight

Started by Taji34, 21 September 2012 - 08:56 PM
Taji34 #1
Posted 21 September 2012 - 10:56 PM
Hey, so this is my first program! It makes a simple 11x11 house. It has 3 2x3 windows and a skylight. Now this is version one, so the house is only made of one material, and I haven't gone through the code and made it more efficient or anything yet, it just works at the moment. Put fuel in slot 1, put the material you want the house built out of in slots 2 -7, glass panes (or glass, your choice) in slot 8, and Glass in slot 9, then run. Here's the code:
Current version: 1.01
Spoiler

a = 10
b = 10
c = 10
function checkStone()
    turtle.getItemCount(2)
    ItemCount1 = turtle.getItemCount(2)
    turtle.getItemCount(3)
    ItemCount2 = turtle.getItemCount(3)
    turtle.getItemCount(4)
    ItemCount3 = turtle.getItemCount(4)
    turtle.getItemCount(5)
    ItemCount4 = turtle.getItemCount(5)
    turtle.getItemCount(6)
    ItemCount5 = turtle.getItemCount(6)
    turtle.getItemCount(7)
    ItemCount6 = turtle.getItemCount(7)
    if ItemCount1 > 1 then
        turtle.select(2)
    elseif ItemCount2 > 1 then
        turtle.select(3)
    elseif ItemCount3 > 1 then
        turtle.select(4)
    elseif ItemCount4 > 1 then
        turtle.select(5)
    elseif ItemCount5 > 1 then
        turtle.select(6)
    elseif ItemCount6 > 1 then
        turtle.select(7)
    else
        write("No stone")
    end
end
function DigWall()
    for i = 1, a do
        turtle.digDown()
        turtle.forward()
    end
    turtle.turnRight()
end
function PlaceFloor()
    for i = 1, b do
        checkStone()
        turtle.placeDown()
        turtle.forward()
    end
    turtle.turnRight()
end
function PlaceWall()
    for i = 1, 10 do
        checkStone()
        turtle.placeDown()
        turtle.forward()
    end
    turtle.turnRight()
end
function PlaceWallDoor()
    for i = 1, 5 do
        checkStone()
        turtle.placeDown()
        turtle.forward()
    end
    turtle.forward()
    for i = 1, 4 do
        checkStone()
        turtle.placeDown()
        turtle.forward()
    end
    turtle.turnRight()
end
function PlaceWindowsFront()
    turtle.turnLeft()
    for i = 1, 2 do
        turtle.up()
        turtle.dig()
        turtle.place()
    end
    turtle.turnRight()
    turtle.forward()
    turtle.turnLeft()
    for i = 1, 2 do
        turtle.dig()
        turtle.place()
        turtle.down()
    end
end
function PlaceWallWindow()
    for i = 1, 4 do
        checkStone()
        turtle.placeDown()
        turtle.forward()
    end
    turtle.select(8)
    for i = 1, 3 do
        turtle.placeDown()
        turtle.forward()
    end
    for i = 1, 3 do
        checkStone()
        turtle.placeDown()
        turtle.forward()
    end
    checkStone()
    turtle.placeDown()
    turtle.turnRight()
end
function PlaceWall2()
    for i = 1, 8 do
        checkStone()
        turtle.placeDown()
        turtle.forward()
    end
    turtle.turnRight()
end
function PlaceGlass()
    for i = 1, c do
        turtle.placeDown()
        turtle.forward()
    end
    turtle.turnRight()
end
turtle.select(1)
turtle.refuel()
for i = 1, 3 do
    DigWall()
end
a = a-1
for i = 1, 9 do
    for i = 1, 2 do
        DigWall()
    end
    a = a-1
end
turtle.digDown()
turtle.turnRight()
for i = 1, 2 do
    for i = 1, 5 do
        turtle.forward()
    end
    turtle.turnRight()
end
for i = 1, 3 do
    PlaceFloor()
end
b = b-1
for i = 1, 9 do
    for i = 1, 2 do
        PlaceFloor()
    end
    b = b-1
end
turtle.placeDown()
turtle.turnRight()
for i = 1, 2 do
    for i = 1, 5 do
        turtle.forward()
    end
    turtle.turnRight()
end
turtle.up()
for i = 1, 3 do
    PlaceWall()
end
PlaceWallDoor()
turtle.up()
for i = 1, 3 do
    PlaceWallWindow()
end
PlaceWallDoor()
turtle.up()
for i = 1, 3 do
    PlaceWallWindow()
end
PlaceWall()
turtle.up()
for i = 1, 4 do
    PlaceWall()
end
turtle.up()
for i = 1, 4 do
    PlaceWall()
end
turtle.turnRight()
for i = 1, 5 do
    turtle.forward()
end
turtle.turnLeft()
PlaceWall()
turtle.turnLeft()
turtle.turnLeft()
for i = 1, 5 do
    turtle.forward()
end
turtle.turnLeft()
for i = 1, 5 do
    turtle.forward()
end
turtle.turnLeft()
PlaceWall()
for i = 1, 4 do
    turtle.forward()
end
turtle.turnRight()
turtle.forward()
for i = 1, 5 do
    PlaceWall2()
end
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
turtle.back()
turtle.select(9)
for i = 1, 3 do
    PlaceGlass()
end
c = c-1
for i = 1, 9 do
    for i = 1, 2 do
        PlaceGlass()
    end
    c = c-1
end
turtle.turnRight()
for i = 1, 2 do
    for i = 1, 5 do
        turtle.forward()
    end
    turtle.turnRight()
end
turtle.turnRight()
turtle.turnRight()
turtle.forward()
for i = 1, 5 do
    turtle.down()
end
turtle.select(8)
turtle.turnLeft()
turtle.forward()
turtle.forward()
PlaceWindowsFront()
turtle.turnRight()
for i = 1, 4 do
    turtle.forward()
end
PlaceWindowsFront()
turtle.turnLeft()
for i = 1, 8 do
    turtle.forward()
end
turtle.turnLeft()
write("Building Finished")

How is it? Any criticism?
Change Log:
Spoiler1.01: Added front wall windows on either side of door, a little bit of cleaning up of the code
1.00: Initial version
Edited on 22 September 2012 - 04:35 PM
Mr. Fang #2
Posted 26 September 2012 - 12:41 AM
Found your pastebin lol!
Taji34 #3
Posted 05 October 2012 - 01:17 AM
Found your pastebin lol!
What? I don't have a pastebin . . .
PonyKuu #4
Posted 05 October 2012 - 09:01 AM
Oh my… I don't like the checkStone function…
I could write it like this:


local function checkStone ()
	for i =2,7 do
		if turtle.getItemCount (i) > 1 then
			turtle.select (i)
			return true
		end
	end
	print "No stone."
	return false
end

This one checks certain slots. But you can make it even better! You can use one slot for reference. Like I made in my tunnel and branching programs:


local function findItem (slot)
	turtle.select (slot)
	for i = 1,16 do
		if i ~= slot then
			if turtle.getItemCount (i) > 0 then
				if turtle.compareTo (i) then
					turtle.select (i)
					return true
				end
			end
		end
	end
	if turtle.getItemCount (slot) > 1 then
		return true
	else
		turtle.select (1)
		print "No items found"
		return false
	end
end

What it does - it searches same item as in given slot in all slots of turtle's inventory, and if it finds any - it selects that slot and returns true. If it doesn't - it checks if the given slot has two or more items (so turtle can use one of them), and if it has - returns true. Otherwise, if there are only one item in the given slot, and no other slots with the same item, it selects the first slot, prints "No items found" and returns false.
rafalpilat0077 #5
Posted 05 October 2012 - 06:38 PM
i know it sounds realy stupid but how do you paste stuff into a computercraft computer?you cant do ctrl+v cuz then it pops up the save of exit menu on the computer