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

Turtle Program - WallPlaster - Code Suggestions / Upgrades

Started by MortymerXT, 31 January 2013 - 06:17 AM
MortymerXT #1
Posted 31 January 2013 - 07:17 AM
Hello!

I recently started playing the Feed The Beast mods and am loving turtles!

Below the cut I have posted my first turtle program. Its purpose is to go up and down a wall and replace all the block spots with cobble.
Some issues I have run into are that it doesn't return and dump if it is full, it can't pick cobble from other slots except the one listed, and if it runs out it just mines ou the entire wall without stopping.

I am doing more research and code reading from other people programs but would love to hear any feedback the Pro's have!

Thanks!!

MortymerXT

Spoiler– Wall Plaster v1.5 by MortymerXT

– Variables

a=1
d=1

– Functions

– Refueling

function JuiceUp()
turtle.select(1)
turtle.refuel(1)
end

function NeedFuelCheck()
if turtle.getFuelLevel() < 10 then
JuiceUp()
else
end
end
– Plaster Up
function plasterup()
NeedFuelCheck()
if turtle.detectUp() == true then
moveover()
d=0
else
turtle.up()
turtle.dig()
turtle.select(2)
turtle.place()
end
end
– Plaster Down
function plasterdown()
NeedFuelCheck()
if turtle.detectDown() == true then
moveover()
d=1
else
turtle.down()
turtle.dig()
turtle.select(2)
turtle.place()
end
end
– Move Over
function moveover()
turtle.turnRight()
if turtle.detect() == false then
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.select(2)
turtle.place()
else
a=0
end
end


– Execution
while a == 1 do
if a == 1 and d == 1 then
plasterup()
else
if a == 1 and d == 0 then
plasterdown()
end
end
end
Lyqyd #2
Posted 31 January 2013 - 09:41 AM
Split into new topic.
OmegaVest #3
Posted 31 January 2013 - 10:43 AM
Alright, so a few things first:

1) Code tags and formatting. It makes it slightly easier on us if you use code tags (not necessarily instead of spoiler tags) on this forum. Also, format you code so that every time you add a conditional (an if statement, or a loops), you indent that line, and every time you end that conditional's effects, you reverse the indent.

BTW: Code tags can be made with the little button on the forum text editor that looks like this: <>

while true do
  if con then
	 --
  elseif con - 1 then
	 --
  else
	 --
   end
end

2) The easiest way to get the program to recognize when to stop is to mark out one slot that will house cobblestone for sure, and then when that slot gets emptied to one block, stop.

function checkCobble()
   if not (turtle.getItemCount(cobbleSlot) > 1) then
	  return false
   else
	  return true
   end
end

And then when you are running your plasterup function's loop, call this line: a = checkCobble. And change a to a boolean, that being true, instead of 1. So, when you run out of cobble, the turtle will know to stop the loop. It's up to you to get it back, though. I suggest having it keep track of it's progress, and moving back that many spaces.

3) Full is an interesting problem. Primarily because, so far as I know, compare still doesn't equate stone and cobblestone, so you will almost always have some runoff. But the easiest thing is to make a function similar to checkCobble that loops through the "store" slots, and when they all have something in them, tell the turtle to stop.
MortymerXT #4
Posted 05 February 2013 - 02:50 AM
Sorry about the messy code, I thought it would keep my format from the copy&amp;paste.

Also thanks for the suggestions!