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

Need a circular floor/platform builder

Started by duranis, 12 January 2013 - 03:09 AM
duranis #1
Posted 12 January 2013 - 04:09 AM
I'm hoping someone has already made a program like this. Basically I have a turtle program that will build a circular tower but I need one that will now fill in a floor at whichever level I place it. ideally I would love to have a program that I can set the inner radius and outer radius and the turtle will then go build circles from the inner radius to the outer one. As they will be quite large having it stop in place when it needs more materials would be great (having it go back to a chest and grabbing materials would be amazing).

I have tried modifying a few circle programs I have found on here but its beyond me at the moment unfortunately.

Are there any scripts out there already that will do this?
ChunLing #2
Posted 12 January 2013 - 04:41 AM
Check the Turtle Programs forum. There is a program posted that does this, if I recall.
duranis #3
Posted 12 January 2013 - 05:14 AM
Thanks but i have checked there. Also done multiple google searches. I have found 1 script that would be perfect as it add's floors to any shaped building but is broken (it only uses first inventory slot and then stops) and another that the description says it does what I want but the link is down.

Only does a 1 wide circle
http://www.computercraft.info/forums2/index.php?/topic/6269-circle-program/page__hl__floor__fromsearch__1

Would be perfect but it only takes items from the first slot then carries on running but doesnt place anything. if this could be fixed it would be great.
http://turtlescripts.com/project/gjdh06-Turtle-Floor-Builder
http://www.youtube.com/watch?v=iihHZpcL7J0

There was another one but I can't find it now. was from a long time ago though and links are dead.
ChunLing #4
Posted 12 January 2013 - 05:25 AM
Oh, if you just need a function to switch inventory slots when one is empty then you can use something like this:
function selectSlot()
    for i=1,16 do
        if turtle.getItemCount(i) ~= 0 then
            turtle.select(i)
        break end
    end
end
Call this before placing, and you'll always be placing something (unless it's an item you can't place or your trying to place it where it can't be placed, you know).
duranis #5
Posted 12 January 2013 - 05:40 AM
I'm sorry but I have no idea where to put this. I'm a complete newb to programming and while I can follow what is going on in a program that is about as far as I go.

The script is below, where about would I put it? I did try but Im stupid :)/>


turningRight = true		-- If the first direction the turtle needs to turn is right, leave this true. Change to false if you need to turn left first.
blocksBetweenLanterns = 15 -- Number of blocks between placing torches

blocksSinceLastLantern = 0
while true do

  -- Place a block below and 2 blocks above
  turtle.placeDown()
  turtle.up()
  turtle.placeUp()
  turtle.down()

  -- Figure out if we need to place a lantern
  blocksSinceLastLantern = blocksSinceLastLantern + 1
  if blocksSinceLastLantern > blocksBetweenLanterns then
	if turtle.getItemCount(9) == 0 then
	  print("Out of Lanterns")
	  print("Place some in slot 9")
	  print("and press ENTER to continue")
	  read()
	end
	turtle.turnRight()
	turtle.turnRight()
	turtle.select(9)
	turtle.place()
	turtle.select(1)
	turtle.turnRight()
	turtle.turnRight()
	blocksSinceLastLantern = 0
  end

  -- If we can't move forward, start the process of moving unto the next row
  if turtle.forward() == false then

	-- Check which direction we need to turn
	if turningRight == true then
	
	  -- Turn Right
	  turtle.turnRight()
	  if turtle.forward() == false then
		clearToContinue = false
		while clearToContinue == false do
		  turtle.turnRight()
		  turtle.forward()
		  turtle.turnLeft()
		  if turtle.forward() == true then
			clearToContinue = true
		  end
		end
	  end
	  turtle.turnLeft()
	  turningRight = false
	else
	
	  -- Turn Left
	  turtle.turnLeft()
	  if turtle.forward() == false then
		clearToContinue = false
		while clearToContinue == false do
		  turtle.turnLeft()
		  turtle.forward()
		  turtle.turnRight()
		  if turtle.forward() == true then
			clearToContinue = true
		  end
		end
	  end
	  turtle.turnRight()
	  turningRight = true
	end
  
	-- Move forward until we hit the wall of the new row
	while turtle.detect() == false do
	  turtle.forward()
	end
  
	-- Turn around
	turtle.turnRight()
	turtle.turnRight()

  end

  -- Check to make sure the inventory has materials
  inventoryEmpty = true
  for i=1,9 do
	if turtle.getItemCount(i) > 0 then
	  inventoryEmpty = false
	  break
	end
  end

  -- Pause if we ran out of stuff
  if inventoryEmpty == true then
	print("Need More Blocks!")
	print("Press Enter To Continue...")
	read()
  end

end

hmmm i really am stupid. I need to set that up as a separate script and then call it within this one…. i think.
ChunLing #6
Posted 12 January 2013 - 09:06 AM
You can define the function up at the top with all the other global variables (functions are just like any other variables in Lua).

Then you call it whenever you might need to switch inventory slots. Probably you would replace that "turtle.select(1)" (you'll also want to change the lantern slot to slot 16 while your at it).

Then instead of only using slot 1 for building blocks, the program will switch to the lowest numbered slot that has anything in it.

That's a pretty basic adaptation, but it should work most of the time.
duranis #7
Posted 12 January 2013 - 01:29 PM
Thanks a lot but I still cant get it to work. I'm sure what your saying is correct but I just cant figure it out. Have a lot to learn unfortunately :(/> Below is what i did and while the program did run it then just made the turtle move around in circles.


function selectSlot()
    for i=1,16 do
	    if turtle.getItemCount(i) ~= 0 then
		    turtle.select(i)
	    break end
    end
end

turningRight = true			 -- If the first direction the turtle needs to turn is right, leave this true. Change to false if you need to turn left first.
blocksBetweenLanterns = 15 -- Number of blocks between placing torches

blocksSinceLastLantern = 0
while true do

  -- Place a block below and 2 blocks above
  turtle.placeDown()
  turtle.up()
  turtle.placeUp()
  turtle.down()

  -- Figure out if we need to place a lantern
  blocksSinceLastLantern = blocksSinceLastLantern + 1
  if blocksSinceLastLantern > blocksBetweenLanterns then
	    if turtle.getItemCount(16) == 0 then
		  print("Out of Lanterns")
		  print("Place some in slot 9")
		  print("and press ENTER to continue")
		  read()
	    end
	    turtle.turnRight()
	    turtle.turnRight()
	    turtle.select(16)
	    turtle.place()
	    function selectSlot()
	    turtle.turnRight()
	    turtle.turnRight()
	    blocksSinceLastLantern = 0
  end

  -- If we can't move forward, start the process of moving unto the next row
  if turtle.forward() == false then

	    -- Check which direction we need to turn
	    if turningRight == true then
	  
		  -- Turn Right
		  turtle.turnRight()
		  if turtle.forward() == false then
			    clearToContinue = false
			    while clearToContinue == false do
				  turtle.turnRight()
				  turtle.forward()
				  turtle.turnLeft()
				  if turtle.forward() == true then
					    clearToContinue = true
				  end
			    end
		  end
		  turtle.turnLeft()
		  turningRight = false
	    else
	  
		  -- Turn Left
		  turtle.turnLeft()
		  if turtle.forward() == false then
			    clearToContinue = false
			    while clearToContinue == false do
				  turtle.turnLeft()
				  turtle.forward()
				  turtle.turnRight()
				  if turtle.forward() == true then
					    clearToContinue = true
				  end
			    end
		  end
		  turtle.turnRight()
		  turningRight = true
	    end

	    -- Move forward until we hit the wall of the new row
	    while turtle.detect() == false do
		  turtle.forward()
	    end

	    -- Turn around
	    turtle.turnRight()
	    turtle.turnRight()

  end

end
ChunLing #8
Posted 12 January 2013 - 05:16 PM
You don't need the function keyword to call a function, you just call it (the same way you're calling all your other functions), so:
turtle.place()
selectSlot()
turtle.turnRight()
duranis #9
Posted 13 January 2013 - 03:51 PM
oh yeah of course! thank you so much. Works perfectly now and I learnt a fair bit in the process :)/>