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

Turtle Filler

Started by d1ng0d0g, 23 May 2013 - 07:06 AM
d1ng0d0g #1
Posted 23 May 2013 - 09:06 AM
It's been some ages since I actually had to code anything. I started out on an island and wanted to make a simple turtle program to extend to island in a simple way (without having to be in water all the time)

It's supposed to start on the dry bit and just fill up everything ahead and to the right of it.

And I'm just starting myself blank on my program. It 'works' with one tiny flaw. Every odd line, is one too short.

http://pastebin.com/Q6TMibZa


The Code
Spoiler

	-- Fills any area, returning for
	-- materials and fuel
	
	local tArg = {...}
	local ToMoveForward
	local ToMoveRight
	
	local locX = 0
	local locY = 0
	local locZ = 0
	
	local SlotIs = 0
	
	function PlaceBlock()
	  while not turtle.placeDown() do
		SlotIs = (SlotIs + 1)%16
		turtle.select(SlotIs + 1)
	  end
	end
	
	function MoveForward()
	  while not turtle.forward() do end
	end
	
	function MoveUp()
	  while not turtle.up() do end
	end
	
	function MoveDown()
	  while not turtle.down() do end
	end
	
	function FillLine()
	  locY = ToMoveForward
	  for Forward = 1, locY do
		while not turtle.detectDown() do
		  MoveDown()
		  locZ = locZ + 1
		end
		for Upward = 1, locZ do
		  MoveUp()
		  PlaceBlock()
		  locZ = locZ - 1
		end
		MoveForward()
	  end
	end
	
	function FillingItUp()
	  locX = ToMoveRight
	  for PlottingAlong = 1, locX do
		FillLine()
		locX = locX + 1
		TurnWhere = locX%2
		if TurnWhere == 0 then
		  turtle.turnLeft()
		  MoveForward()
		  turtle.turnLeft()
		else
		  turtle.turnRight()
		  MoveForward()
		  turtle.turnRight()
		end
		
	  end
	end
	
	if #tArg ~= 2 then
	  print("Usage: filler <forward> <right> (positives only)")
	  return
	end
	
	ToMoveForward = tonumber(tArg[1])
	ToMoveRight = tonumber(tArg[2])
	
	FillingItUp()

Lyqyd #2
Posted 24 May 2013 - 01:28 PM
Split into new topic.
James0x57 #3
Posted 24 May 2013 - 04:46 PM
Try this for the FillingItUp function:


function FillingItUp()
  for locX = 1, ToMoveRight do
    FillLine()
    if (locX%2) == 0 then
	  turtle.turnLeft()
	  MoveForward()
	  turtle.turnLeft()
    else
	  turtle.turnRight()
	  MoveForward()
	  turtle.turnRight()
    end
  end
end

Logic was a bit weird, though I'm not sure what would have caused one of the directions* to be one too short on odd rows.
* which direction shows up short?

Also, not important for the program at all, but up and down coordinate in 3D enviornments is usually Y. =)
d1ng0d0g #4
Posted 25 May 2013 - 04:48 AM
Updated the code a little: http://pastebin.com/RKZwZmJY

And found where I made the code do something I did not intend it to do.



-- Move foward up to defined distance
-- and if there's space below, fill it.
function FillLine()
  for locZ = 1, ToMoveForward do
    while not turtle.detectDown() do
      MoveDown()
      locY = locY + 1
    end
    for Upward = 1, locY do
      MoveUp()
      PlaceBlock()
      locY = locY - 1
    end
    MoveForward()
  end
end

ToMoveForward times it moves down and then forward, then it turns into the next row and does the same. But this causes the line to be sawtoothed staggered.