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

House Builder After Choise Size

Started by plazter, 28 September 2013 - 04:25 PM
plazter #1
Posted 28 September 2013 - 06:25 PM
Hello out there in the great world!

- ive spend my night makeing a program that can build a House after your input :D/>
its quite simple to understand but even more simple to use :D/>

All you need to do when you want to build a house with your turtle is:
<program name> <width> <height> – Woila! the turtle goes up and start building your house ;)/>

Example: BuildMeAHouse 6 5

pastebin: http://pastebin.com/ThTv6i3G

Spoiler

-- Code by Plazter --
-- 2013 --
-- House builder --
-- Description: This is a turtle program, to build houses as you wish, right now it can only take a even number
--Heres an example on how to start it to build: Build 4=the widht. 3= the height of the house

local args = {...}
turtle.up()

if args[1] == nil or args[1] == "help" then
	print("<program name> <width> <Height>")
  return
end

local slot = 1

function wall()
  for i = 1,args[1] -1 do
   turtle.placeDown()
	turtle.forward()
  if turtle.getItemCount(slot) < 1 then
   slot = slot+1
	turtle.select(slot)
  end
end
end

function right()
  turtle.turnRight()
end

function left()
  turtle.turnLeft()
end


function square()
	 wall()
	 right()
	 wall()
	 right()
	wall()
	right()
	wall()
	 right()
end

function roof() -- Work in progress
  for i = 1,args[1] /2 do
   wall()
	right()
   turtle.placeDown()
   turtle.forward()
   right()
   wall()
   left()
   turtle.placeDown()
turtle.forward()
  left()
end
   turtle.back()
	for i = 1,args[2] +1 do
	 turtle.down()
  right()
  right()
end
end

function layer()
  for i = 1, args[2] do
	 square()
   turtle.up()
  end
end

-- The program --
layer()
roof()
print("Done building..")

Hope you like it :)/>
Regards Plazter

Ps. You can make it uneven number still but then it will derp on the roof :b


EDIT1: Noticed that it is currently kinda broke.. i just downloaded it to a turtle and it is only placeing every second block for some reason, if you get this fail aswell, let me know, i will work on the code when i got the time for it again.

EDIT2: That is only when i try to do the "while turtle.forward() == false do" :/
jamd315 #2
Posted 29 September 2013 - 05:38 AM
Very smart. I like how simple it is, using functions instead of repetitive code. :)/>
plazter #3
Posted 29 September 2013 - 01:16 PM
Thanks:D
plazter #4
Posted 29 September 2013 - 01:27 PM
Im on my phone, sorry for double post, but might add a refuel system :)/>
kelm #5
Posted 27 October 2013 - 03:53 PM
I started using your program to build myself something really big, and it crashed when it ran out of blocks. I made the following change to make it hang and wait for more blocks when it runs out instead of crashing.

I added this variable.

local stack = 0

This function

function findBlock()
  slot = 0
  stack = 0
  for i = 1, 16, 1 do
	if turtle.getItemCount(i) > 0 then
	  slot = i
	  turtle.select(slot)
	  stack = turtle.getItemCount(i)
	  break
	end
  end
  if slot == 0 then
	return false
  else
	return true
  end
end

And changed this one

function wall()
  for i = 1,args[1] -1 do
	if stack == 0 then
	  while not findBlock() do end
	end
	turtle.placeDown()
	stack = stack - 1
	turtle.forward()
  end
end
StrykerC #6
Posted 01 November 2013 - 12:16 AM
Ok, I've tried running this program, I keep digging through tutorials and finding nothing, so maybe someone here can explain this to me. Why when I run this program as is the turtle just spins around and eventually says the building is done?
Bomb Bloke #7
Posted 01 November 2013 - 03:28 AM
My guess is the turtle has no fuel (the code doesn't appear to check for that).

Before running this script, throw a stack of eg charcoal in one of its inventory slots then type "refuel all" into the command line. Other items accepted as fuel are listed here. One unit of fuel is consumed for every block the turtle travels.
StrykerC #8
Posted 01 November 2013 - 04:48 AM
yep that fixed it. Thanks much appreciated.
plazter #9
Posted 24 February 2014 - 04:26 PM
Hey sorry for being inactive, i will resume this code and use the fix'es you've made, and update this thread when done, and glad some people can answer when i forget to check ;)/> Thanks ^^
LDDestroier #10
Posted 16 December 2014 - 10:23 PM
Try changing the program to allow multiple stories! Like, a height of 3 and 4 stories would make a house about 12 blocks tall. Also, your program does not support separate widths and lengths.
Edited on 16 December 2014 - 09:36 PM