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

variable size building builder

Started by Roonagooo, 02 February 2013 - 11:04 PM
Roonagooo #1
Posted 03 February 2013 - 12:04 AM
here is my first program that i have just recently finished just though i might share it with the comunity if anyone has any additions they would like me to make feel free to post a comment also feel free to critique my code
also here is a pastebin link if you want to use this program.
edit: just noticed that there are stll some of my own comments in there sorry about that :P/>/>
http://pastebin.com/xnmQqL4W for version 1.4
If you do find a problem please tell me what it is so I can fix it instead of just telling me there is a problem.

if there are any fetures that you would like added please tell me.
features to be added

1)if not enough blocks of the correct type will pause and wait for more.
eta) 1-2 weeks im fairly busy with work at the moment.


function instructions()
--here are the instructions for the program.
print "please place 1 of the material you want the floor made from in slot 13"
print "please place 1 of the item you want the walls made out of in slot 14"
print "please place 1 of the item you want to make the roof our of in slot 15"
print "please place fuel in slot 16"
end
-- investigate ways to shrink this code
-- this is my function to compair the
-- items in the first 12 slots of the turtle
-- capable of compairing to any slot in the turtle
-- need to make a check to make sure it
-- is not compairing to itself.
function comp(t)
   turtle.select(1)
  if turtle.compareTo(t) == true
   then s = 1
   return s
   else turtle.select(2)
  end
  if turtle.compareTo(t) == true
   then s = 2
   return s
   else turtle.select(3)
  end
  if turtle.compareTo(t) == true
   then s = 3
   return s
   else turtle.select(4)
  end
  if turtle.compareTo(t) == true
   then s = 4
   return s
   else turtle.select(5)
  end
  if turtle.compareTo(t) == true
   then s = 5
   return s
   else turtle.select(6)
  end
  if turtle.compareTo(t) == true
   then s = 6
   return s
   else turtle.select(7)
  end
  if turtle.compareTo(t) == true
   then s = 7
   return s
   else turtle.select(8)
  end
  if turtle.compareTo(t) == true
   then s = 8
   return s
   else turtle.select(9)
  end
  if turtle.compareTo(t) == true
   then s = 9
   return s
   else turtle.select(10)
  end
  if turtle.compareTo(t) == true
   then s = 10
   return s
   else turtle.select(11)
  end
  if turtle.compareTo(t) == true
   then s = 11
   return s
   else turtle.select(12)
  end
  if turtle.compareTo(t)
   then s = 12
   return s
   else print "no valid materials"
  end
end
--this function allows for the choosing
-- of the dimensions of the building
function getDim(x,y,z)
print "please enter desired length:"
l = io.read()
print "please enter desired width:"
w = io.read()
print "please enter desired height:"
h = io.read()
print (l..w..h)
return l, w, h
end
--floor building function
function floor(x,t,c )
t = 13
comp(t,c)
c = s
for i = 1, x do
turtle.digDown()
turtle.placeDown()
if turtle.getItemCount(c) == 0
  then comp(t,c)
  c = s
end
forward()
end
for i = 1, x do
turtle.back()
end
turtle.turnRight()
forward()
turtle.turnLeft()
fuel(c)
end
--wall building function
function walls(x,y,t,c)
t = 14
comp(t,c)
c = s
turtle.placeDown()
for k = 1 , x-1
do forward()
  turtle.placeDown()
  if turtle.getItemCount(c) == 0
   then comp(t,c)
   c = s
  end
  fuel(c)
end
turtle.turnRight()
forward()
for i = 1 , y-2
  do if turtle.getItemCount(c) == 0
  then comp(t,c)
  c = s
  end
  turtle.placeDown()
  forward()
end
fuel(c)
turtle.turnRight()
end

-- this is the function to make the roof
function roof(x,y,t,c)
t = 15
comp(t,c)
c = s
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.down()
for i = 1 , x-2
  do for j = 1, y-2
   do if turtle.getItemCount(c) == 0
		then
		comp(t,c)
		c = s
		end
	   turtle.placeDown()
	   turtle.forward()
   end
	for k= 1, y-2
	 do turtle.back()
	end
	turtle.turnLeft()
	forward()
	turtle.turnRight()
  end	
end

-- refueling function
function fuel(c)
if turtle.getFuelLevel() <=500
then turtle.select(16)
turtle.refuel(2)
print(turtle.getFuelLevel())
turtle.select(c)
end
end
-- functions included to reduce lines of code
-- and to allow for a stuck check
function forward()
if turtle.forward() ~= true
  then turtle.dig() turtle.forward()
end
end
function up()
if turtle.up() ~= true
  then turtle.digup()
	 turtle.up()
	 fuel(c)
  else fuel(c)
end
end

-- main program
local x, y, z, t, c
instructions()
--sleep(7)
getDim()
x = l
y = w
z = h
print (x..y..z)
for j= 1, y do
floor(x,t,c)
end
turtle.turnLeft()
for j= 1, y do
forward()
end
turtle.turnRight()
up()
for l= 1 , z
do
   for m = 1 , 2
	do
  walls(x,y,t,c)
end
up()
end
roof(x,y,t,c)
turtle.turnRight()
for i = 1 , x
do forward()
end
turtle.turnRight()
forward()
turtle.turnLeft()
for j = 1 . z
do turtle.down
end
bjornir90 #2
Posted 03 February 2013 - 02:12 AM
I think you should ask for this to be moved on the turtle forum :)/>
Roonagooo #3
Posted 03 February 2013 - 12:40 PM
Yea I thought about that a while ago so as was stated above could any mods please move this to the turtle forum please and thank you.
Skullblade #4
Posted 03 February 2013 - 12:48 PM
Report it and ask for it to be moved
Mc_gee #5
Posted 10 February 2013 - 10:28 AM
i think you need to rewrite it because there are some faults in the program
DBArcAngel #6
Posted 10 February 2013 - 01:04 PM
i think you need to rewrite it because there are some faults in the program
It would be helpful and courteous to let him know if you have found a fault, instead of just putting what you put in this comment!
Roonagooo #7
Posted 10 February 2013 - 07:05 PM
i think you need to rewrite it because there are some faults in the program
It would be helpful and courteous to let him know if you have found a fault, instead of just putting what you put in this comment!

I second this it would be most helpful to know the what faults and problems you think there are in the program are.
Mc_gee #8
Posted 11 February 2013 - 02:09 AM
i think you need to rewrite it because there are some faults in the program
It would be helpful and courteous to let him know if you have found a fault, instead of just putting what you put in this comment!

I second this it would be most helpful to know the what faults and problems you think there are in the program are.

bios:338: [string "builder"]:222: 'do' expected
Mc_gee #9
Posted 11 February 2013 - 02:17 AM
and did you ever tried the program in minecraft
Roonagooo #10
Posted 11 February 2013 - 12:36 PM
Yes I did it is working in my world ill look into it though and update the program thank you

Edit eta done

i accidently posted the 1.3 version which was evidently missing a do line. I appologise about that.
Mc_gee #11
Posted 12 February 2013 - 01:13 AM
Yes I did it is working in my world ill look into it though and update the program thank you

Edit eta done

i accidently posted the 1.3 version which was evidently missing a do line. I appologise about that.
no problem
maxymunte #12
Posted 17 March 2013 - 04:15 AM
i made somthing like this maby you could tak over somthing of mine its working and 99% bug free
this is my first program

Spoiler


if turtle.getFuelLevel() < 1000 then
turtle.select(16)
turtle.refuel(10)
end
while turtle.detectDown() == false do
turtle.down()
end
turtle.up()
term.clear()
term.setCursorPos(1,1)
print("how wide should the house be?")
write("enter a number : ")
local var1 = tonumber(read())
term.clear()
term.setCursorPos(1,1)
print("how long should the house be?")
write("enter a number : ")
local var2 = tonumber(read())
term.clear()
term.setCursorPos(1,1)
print("how high should the house be?")
write("enter a number : ")
local var3 = tonumber(read())
local var1 = tonumber(var1 - 2)
local var2 = tonumber(var2 - 2)
local totali = (((var1+var2)*2)*var3)+(var3*4)+(var1*var2)
local print1 = ((var1+var2)*2)*var3
local print2 = var3*4
local print3 = var1*var2
term.clear()
term.setCursorPos(1,1)
print("---------------------------------------")
print("row 1 = wall, row 2 = corners, row 3 = roof")
print("---------------------------------------")
print("items required row 1: ", print1)
print("items required row 2: ", print2)
print("items required row 2: ", print3)
print("---------------------------------------")
print("total items required: ", totali)
print("---------------------------------------")
print("press any key to continue")
event1, param1 = os.pullEvent()
term.clear()
term.setCursorPos(1,1)
print("calculating")
local getItem1 = tonumber(turtle.getItemCount(1) + turtle.getItemCount(2) + turtle.getItemCount(3) + turtle.getItemCount(4))
local itemState1 = false
local need1 = 0
term.clear()
term.setCursorPos(1,1)
if getItem1 < print1 and getItem1 < 256 then
while itemState1 == false do
  if getItem1 > 256 then need1 = tonumber(256) else need1 = tonumber(print1) end
   if getItem1 < print1 and getItem1 < 256 then
   sleep(0.2)
   itemState1 = false
   term.clear()
   term.setCursorPos(1,1)
   print("need more resources in row 1 to be able to finish this build")
   print("---------------------------------------")
   print("items in inventory: ",getItem1)
   print("you require atleast: ",need1)
   print("still needed: ",need1 - getItem1)
   print("---------------------------------------")
   getItem1 = tonumber(turtle.getItemCount(1) + turtle.getItemCount(2) + turtle.getItemCount(3) + turtle.getItemCount(4))
  else
   term.clear()
   term.setCursorPos(1,1)
   print("need more resources in row 1 to be able to finish this build")
   print("---------------------------------------")
   print("items in inventory: ",getItem1)
   print("you require atleast: ",need1)
   print("still needed: ",need1 - getItem1)
   print("---------------------------------------")
   print("press any key to continue")
   itemState1 = true
   event1, param1 = os.pullEvent()
   sleep(1)
  end
end
end
local getItem2 = tonumber(turtle.getItemCount(5) + turtle.getItemCount(6) + turtle.getItemCount(7) + turtle.getItemCount(8))
local itemState2 = false
local need2 = 0
if getItem2 < print2 and getItem2 < 256 then
while itemState2 == false do
  if getItem2 > 256 then need2 = tonumber(256) else need2 = tonumber(print2) end
   if getItem2 < print2 and getItem2 < 256 then
   sleep(0.2)
   itemState2 = false
   term.clear()
   term.setCursorPos(1,1)
   print("need more resources in row 2 to be able to finish this build")
   print("---------------------------------------")
   print("items in inventory: ",getItem2)
   print("you require atleast: ",need2)
   print("still needed: ",need2 - getItem2)
   print("---------------------------------------")
   getItem2 = tonumber(turtle.getItemCount(5) + turtle.getItemCount(6) + turtle.getItemCount(7) + turtle.getItemCount(8))
  else
   term.clear()
   term.setCursorPos(1,1)
   print("need more resources in row 2 to be able to finish this build")
   print("---------------------------------------")
   print("items in inventory: ",getItem2)
   print("you require atleast: ",need2)
   print("still needed: ",need2 - getItem2)
   print("---------------------------------------")
   print("press any key to continue")
   itemState2 = true
   event1, param1 = os.pullEvent()
   sleep(1)
  end
end
end
local getItem3 = tonumber(turtle.getItemCount(9) + turtle.getItemCount(10) + turtle.getItemCount(11) + turtle.getItemCount(12))
local itemState3 = false
local need3 = 0
if getItem3 < print3 and getItem3 < 256 then
while itemState3 == false do
  if getItem3 > 256 then need3 = tonumber(256) else need3 = tonumber(print3) end
   if getItem3 < print3 and getItem3 < 256 then
   sleep(0.2)
   itemState3 = false
   term.clear()
   term.setCursorPos(1,1)
   print("need more resources in row 3 to be able to finish this build")
   print("---------------------------------------")
   print("items in inventory: ",getItem3)
   print("you require atleast: ",need3)
   print("still needed: ",need3 - getItem3)
   print("---------------------------------------")
   getItem3 = tonumber(turtle.getItemCount(9) + turtle.getItemCount(10) + turtle.getItemCount(11) + turtle.getItemCount(12))
  else
  term.clear()
	term.setCursorPos(1,1)
   print("need more resources in row 3 to be able to finish this build")
   print("---------------------------------------")
   print("items in inventory: ",getItem3)
   print("you require atleast: ",need3)
   print("still needed: ",need3 - getItem3)
   print("---------------------------------------")
   print("press any key to continue")
   itemState3 = true
   event1, param1 = os.pullEvent()
   sleep(1)
  end
end
end
term.clear()
term.setCursorPos(1,1)
print("starting to build")
function antiObstruct()
if turtle.detectDown() then
  turtle.digDown()
end
if turtle.detect() then
  turtle.dig()
end
end
function refillMain()
if turtle.getItemCount(1) < 1 then
  if turtle.getItemCount(2) < 1 then
   if turtle.getItemCount(3) < 1 then
	if turtle.getItemCount(4) < 1 then
	 while turtle.getItemCount(1) < 1 do
	  print("need more resources to continue, refill resources")
	  print("press any key to continue")
	  event1, param1 = os.pullEvent()
	  turtle.select(2)
	  turtle.transferTo(1)
	  turtle.select(3)
	  turtle.transferTo(1)
	  turtle.select(4)
	  turtle.transferTo(1)
	  term.clear()
	  term.setCursorPos(1,1)
	 end
	else
	 turtle.select(2)
	 turtle.transferTo(1)
	 turtle.select(3)
	 turtle.transferTo(1)
	 turtle.select(4)
	 turtle.transferTo(1)
	end
   else
	turtle.select(2)
	turtle.transferTo(1)
	turtle.select(3)
	turtle.transferTo(1)
   end
  else
   turtle.select(2)
   turtle.transferTo(1)
  end
end
end
function refillSecundairy()
if turtle.getItemCount(5) < 1 then
  if turtle.getItemCount(6) < 1 then
   if turtle.getItemCount(7) < 1 then
	if turtle.getItemCount(8) < 1 then
	 while turtle.getItemCount(5) < 1 do
	  print("need more resources to continue, refill resources")
	  print("press any key to continue")
	  event1, param1 = os.pullEvent()
	  turtle.select(6)
	  turtle.transferTo(5)
	  turtle.select(7)
	  turtle.transferTo(5)
	  turtle.select(8)
	  turtle.transferTo(5)
	  term.clear()
	  term.setCursorPos(1,1)
	 end
	else
	 turtle.select(6)
	 turtle.transferTo(5)
	 turtle.select(7)
	 turtle.transferTo(5)
	 turtle.select(8)
	 turtle.transferTo(5)
	end
   else
	turtle.select(6)
	turtle.transferTo(5)
	turtle.select(7)
	turtle.transferTo(5)
   end
  else
   turtle.select(6)
   turtle.transferTo(5)
  end
end
end
function refillTertiary()
if turtle.getItemCount(9) < 1 then
  if turtle.getItemCount(10) < 1 then
   if turtle.getItemCount(11) < 1 then
	if turtle.getItemCount(12) < 1 then
	 while turtle.getItemCount(9) < 1 do
	  print("need more resources to continue, refill resources")
	  print("press any key to continue")
	  event1, param1 = os.pullEvent()
	  turtle.select(10)
	  turtle.transferTo(9)
	  turtle.select(11)
	  turtle.transferTo(9)
	  turtle.select(12)
	  turtle.transferTo(9)
	  turtle.select(9)
	  term.clear()
	  term.setCursorPos(1,1)
	 end
	else
	 turtle.select(10)
	 turtle.transferTo(9)
	 turtle.select(11)
	 turtle.transferTo(9)
	 turtle.select(12)
	 turtle.transferTo(9)
	 turtle.select(9)
	end
   else
	turtle.select(10)
	turtle.transferTo(9)
	turtle.select(11)
	turtle.transferTo(9)
	turtle.select(9)
   end
  else
   turtle.select(10)
   turtle.transferTo(9)
   turtle.select(9)
  end
end
end
sleep(4)
term.clear()
print("building")
for n=1,1 do
for i=1,var3 do
  for j=1,2 do
   for k=1,var2 do
	turtle.select(1) -- building main wall
	antiObstruct()
	turtle.placeDown()
	refillMain()
	turtle.forward()
   end
   turtle.turnLeft() -- building corner
   turtle.select(5)
   antiObstruct()
   turtle.placeDown()
   refillSecundairy()
   turtle.forward()
   for l=1,var1 do
	turtle.select(1) -- building main wall
	antiObstruct()
	turtle.placeDown()
	refillMain()
	turtle.forward()
   end
   turtle.turnLeft() -- building corner
   turtle.select(5)
   antiObstruct()
   turtle.placeDown()
   refillSecundairy()
   turtle.select(1)
   turtle.forward()
  end
  turtle.up()
end
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
turtle.select(9)
turtle.down()
turtle.placeDown()
turtle.forward()
local roofvar = tonumber(var1 / 2)
local var2 = tonumber(var2 - 2)
for o=1,roofvar do -- building roof
  for p=1,var2 do
   antiObstruct()
   turtle.placeDown()
   refillTertiary()
   turtle.forward()
  end
  turtle.turnLeft() -- Turning back
  antiObstruct()
  turtle.placeDown()
  refillTertiary()
  turtle.forward()
  turtle.turnLeft()
  antiObstruct()
  turtle.placeDown()
  refillTertiary()
  turtle.forward()
  for p=1,var2 do -- building roof
   antiObstruct()
   turtle.placeDown()
   refillTertiary()
   turtle.forward()
  end
  turtle.turnRight()  -- Turning back
  antiObstruct()
  turtle.placeDown()
  refillTertiary()
  turtle.forward()
  turtle.turnRight()
  antiObstruct()
  turtle.placeDown()
  turtle.forward()
end
for p=1,var2 do -- building roof
  turtle.placeDown()
  refillTertiary()
  turtle.forward()
end
end
turtle.placeDown()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.turnLeft()
for n=1,var3 do
turtle.down()
end
local var2 = tonumber(var2 - 1)
for q=1,var2 do
if turtle.detect() then
  turtle.dig()
end
turtle.forward()
end
turtle.turnLeft()
turtle.turnLeft()
term.clear()
term.setCursorPos(1,1)
print("Done!")
event1, param1 = os.pullEvent()
Roonagooo #13
Posted 18 March 2013 - 12:47 PM
I don't think I'll take over that one but I do plan on improving the program when life gets a bit less hectic