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

House Building Program Base

Started by dylanrhodes0, 09 May 2013 - 06:00 PM
dylanrhodes0 #1
Posted 09 May 2013 - 08:00 PM
Hello! So my HOPE is to get a base for a program to build a house. What I want it to do isn't to hard, I don't think. But here's the outline that I have for it. I am somewhat new to programming so some things may be wrong. http://pastebin.com/S8pKkrTH

-1-10 are the variables. Read comments in code.

-12-24 is a function to get the current Pos of the turtle. My hope is to not use the gps command, but have it keep it to its self(I guess). As well as update each time it moves.

-26-27 is for a goHome() function, again using the hx, hy, hz, and x, y, z, variables.

-29-30 is a function to check how much materials it has. My plan for this is to NOT have to be the amount it needs, but stop when it runs out and "goHome()" to get more stuff, assuming there is more.

-32-33 is to make the floor.

-35-36 is to make the walls of the house.

-38-39 is to make the roof.

Also, I do not believe the commands for the house it self matter, but if they do I can post a world with the house.
Lyqyd #2
Posted 10 May 2013 - 09:45 AM
Split into new topic.
W00dyR #3
Posted 10 May 2013 - 10:47 AM
Ive once bothered making something like this, it was really simple though and not advanced, its pretty much the same over and over :P/>

- First a script to clear the area
- Simple part to dig out a few areas (for a nice basement)
- Simple part to dump blocks every now and then
- Grab blocks from chest to build
- Placing the blocks in the way you want the walls to be there
- Placing the blocks for the roof

Spoiler

local function floor()
length1 = 33 -- length of the floor part
width1 = 13 -- width of the floor part

turtle.turnRight()			 -- positioning the turtle to where the floor goes
for i = 1, 27 do
   turtle.forward()
end
turtle.turnLeft()
turtle.forward()			  -- positioning ends here
for i = 1, length1 do
   turtle.turnRight()
   for i = 1, width1 do
	blockbelow()
	turtle.forward()
   end
   for i = 1, width1 do
	turtle.back()
   end
   turtle.turnLeft()
   turtle.forward()
end
for i = 1, length1 do
   turtle.back()
end
turtle.back()							 -- moving turtle back to starting point
turtle.turnRight()
for i = 1, 27 do
   turtle.back()
end
turtle.turnLeft()
end

That code is for a simple floor part, you can repeat this code and/or add parts to it to make different shapes (including editing parts for the positioning btw)


Spoiler

local function outerwall()
turtle.turnRight()	  -- positioning again
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.up()
turtle.forward()			-- positioning ends here
for i = 1, 5 do			   -- the 5 in this loop is the height of the floors (since at the end it does turtle.up() )
  for i = 1, 14 do		   -- the same part repeated over and over, the 14 in this means how long the wall is)
   turtle.forward()		 -- goes forward
   blockbelow()			 -- places a block below (including a check for making sure it has enough blocks in its selected slot, ill post this below)
  end							-- ends the block placement loop
  turtle.turnRight()		-- makes a turn for the next part of the wall (if it hits a corner)
  for i = 1, 5 do			 -- same thing repeated for a different situation
   turtle.forward()
   blockbelow()
  end
  turtle.turnLeft()
  for i = 1, 5 do
   turtle.forward()
   blockbelow()
  end
  turtle.turnLeft()
  for i = 1, 7 do
   turtle.forward()
   blockbelow()
  end
  turtle.turnRight()
  for i = 1, 19 do
   turtle.forward()
   blockbelow()
  end
  turtle.turnRight()
  for i = 1, 25 do
   turtle.forward()
   blockbelow()
  end
  turtle.turnRight()
  for i = 1, 4 do
   turtle.forward()
   blockbelow()
  end
  turtle.turnLeft()
  for i = 1, 15 do
   turtle.forward()
   blockbelow()
  end
  turtle.turnRight()
  for i = 1, 34 do
   turtle.forward()
   blockbelow()
  end
  turtle.turnRight()
  for i = 1, 14 do
   turtle.forward()
   blockbelow()
  end
  turtle.turnRight()
  for i = 1, 2 do
   turtle.forward()
   blockbelow()
  end
  turtle.turnLeft()
  for i = 1, 4 do
   turtle.forward()
   blockbelow()
  end
  turtle.turnLeft()
  for i = 1, 2 do
   turtle.forward()
   blockbelow()
  end
  turtle.turnRight()
  for i = 1, 8 do
   turtle.forward()
   blockbelow()
  end
  for i = 1, 3 do
   turtle.forward()
  end
  for i = 1, 9 do
   turtle.forward()
   blockbelow()
  end
  turtle.turnRight()
  turtle.up()
end
turtle.turnLeft()      -- positioning back to starting point from here
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.select(1)
end

This part is the part for putting up the walls, its built up the same pretty much (all the things in it, are copied from what my house looked like)

These script are all just copied, I put some helpfull comments in there but it will give you a general idea of a simple way to do this (in my opinion atleast :P/>)

The blockbelow function is here, it checks how many items it has in its selected slot, if its 0 it selects the next slot, and then places a block. (It does not keep in mind when it used up all slots, but that is an easy fix)

Spoiler

local slot = 1
local function blockbelow()
while turtle.getItemCount(slot) == 0 do
  slot = slot + 1
  turtle.select(slot)
end
turtle.placeDown()
end

Might be a bit of a messy post, but as I said, should give you a general idea of how to do it, let me know if you have any questions :)/>
PixelToast #4
Posted 10 May 2013 - 10:49 AM
a better input function

function getPos()
print("Hello!")
print("What is my location?")
write("X: ")
x = tonumber(read())
write("Y: ")
y = tonumber(read())
write("Z: ")
z = tonumber(read())
print("North=1, East=2, South=3, West=4")
write("Dir: ")
d=tonumber(read())
end
dylanrhodes0 #5
Posted 10 May 2013 - 12:28 PM
So here's the world with the house on it. (-124 64 340~ish, can't miss it at night.) Hopefully this won't make things harder.
https://www.dropbox.com/s/l4en2h09pry3o5t/world.rar
And let me know if I'm asking for a miracle, lol.