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

Tower Builder V2

Started by EpicTreeMiner, 13 January 2013 - 05:44 AM
EpicTreeMiner #1
Posted 13 January 2013 - 06:44 AM
I recently finished the code for a tower builder program. It builds a full circle with a 10 block diameter and then moves up and loops, im working on the setting for a glass block row every 6 rows.
It has about 80 lines of code and you define the height of the tower in the program. It even builds a ladder up the inside edge (in development still)

Thanks
Luke

Finished code:

Spoilerprint("Build tower how high?")

local x = tonumber( read() )
term.clear()
– slotCheck NEEDS cleaning up, help?
function slotCheck()
if turtle.getItemCount(1) <2 then
if turtle.getItemCount(2) <2 then
if turtle.getItemCount(3) <2 then
if turtle.getItemCount(4) <2 then
if turtle.getItemCount(5) <2 then
if turtle.getItemCount(6) <2 then
if turtle.getItemCount(7) <2 then
if turtle.getItemCount(8) <2 then
if turtle.getItemCount(9) <2 then
print("Add Items…")
end
end
end
end
end
end
end
end
end
end
for o = 1,(x) do
slotCheck()
else
for i = 1,4 do
turtle.placeDown()
turtle.forward()
turtle.placeDown()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.placeDown()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.placeDown()
turtle.forward()
end
turtle.up()
end
end

PS. I have only been using lua for 2 days now, thats why this is such a simple program.

http://pastebin.com/n4t0wFMV (Code Link) :lol:/>
sjele #2
Posted 13 January 2013 - 07:03 AM

slotCheck = function()
needFill = {} --Slots that needs something to fill them with
slots = ""
for i = 1, 9 do --Looping through the slots
  if turtle.getItemCount(i) <= 1 then
	table.insert(needFill, #needFill+1, i)
  end
end
for loc = 1, #needFill do
  slots = slots.." , "..tonumber(needFill[loc])
end
print("The slots: "..slots.." needs items in them")
end
This should clean up your slotCheck function a bit.
If you have 1 or less item in slots 1, 4 and 5 it should say:
The slots: 1, 4, 5 , needs items in them
EpicTreeMiner #3
Posted 13 January 2013 - 07:54 AM

slotCheck = function()
needFill = {} --Slots that needs something to fill them with
slots = ""
for i = 1, 9 do --Looping through the slots
  if turtle.getItemCount(i) <= 1 then
	table.insert(needFill, #needFill+1, i)
  end
end
for loc = 1, #needFill do
  slots = slots.." , "..tonumber(needFill[loc])
end
print("The slots: "..slots.." needs items in them")
end
This should clean up your slotCheck function a bit.
If you have 1 or less item in slots 1, 4 and 5 it should say:
The slots: 1, 4, 5 , needs items in them

I actually thought about doing that, but considering you only use one block type for the tower (hopefully), when you run out of blocks in slot 1, it automatically takes from slot 2, etc, so in the end if it needs blocks, it needs them in ALL slots. :)/> but nice code and feel free to add it and improve it
EpicTreeMiner #4
Posted 14 January 2013 - 12:39 AM
Bump, anyone have any intrest?
MrHohenheim #5
Posted 14 January 2013 - 01:55 AM
i testing now

not working pastebin get n4t0wFMV 1

bios:338: [string "1"]:27: 'end'
expected (to close 'for' at line 25)
Edited on 14 January 2013 - 01:01 AM
pielover88888 #6
Posted 14 January 2013 - 10:13 AM
Goodness, PLEASE, use spoilers or a pastebin link, instead of having the code in the post, as it get's long lol. Otherwise, that seems pretty cool.