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

Pet Turtles! because who doesn't want a pet robot?

Started by goreae, 06 November 2012 - 02:52 PM
goreae #1
Posted 06 November 2012 - 03:52 PM
I'm not the best programmer in the world, and I just started messing with CC a few days ago, but I'm pretty proud of this.

my inspiration for this useless program is, when I first tried CC in tekkit, I thought that turtles could be kept as pets. I was horribly disappointed now, a month later, I decided to make a program that would make turtles act similar to vanilla mobs. the pathfinding isn't the best, but the turtle usually stays on the ground (or on your chests) and can walk up and down stairs. it's meant to be the startup program, but it can be used as a standalone program. it has no way of retrieving fuel, but will refuel when it needs to with the coal you put into the first slot. this is an impractical program that serves no specific purpose except for pet robots. because why not?

Pastebin: pastebin.com/SHZvURiZ (computer command pastebin get SHZvURiZ [codename])

Source Code:


function forward(n)
  for i=1,n do
	if not turtle.detectDown() then
	  turtle.down()
	end
	if not turtle.forward() then
	  if not turtle.detectDown() then
		turtle.down()
	  end
	  if not turtle.up() then
		break
	  end
	  if not turtle.forward() then
		turtle.down()
		break
	  end
	end
	if not turtle.detectDown() then
	  turtle.down()
	end
  end
end
function right(n)
  turtle.turnRight()
  forward(n)
end
function left(n)
  turtle.turnLeft()
  forward(n)
end
function back(n)
  turtle.turnRight()
  turtle.turnRight()
  forward(n)
end
local L=0
while L==0 do
  dir=math.random(1,4)
  n=math.random(1,4)
  if dir==1 then
	forward(n)
  end
  if dir==2 then
	right(n)
  end
  if dir==3 then
	back(n)
  end
  if dir==3 then
	left(n)
  end
  if turtle.getFuelLevel()<100 then
	turtle.refuel()
  end
  if not (math.random(1,4)==1) then
	sleep(math.random(1,5))
  end
end
Shnupbups #2
Posted 10 November 2012 - 08:29 PM
There is an error on line 52. You forgot to put spaces between turtle.getFuelLevel() and < and 100.
rhyleymaster #3
Posted 10 November 2012 - 08:33 PM
Why not create something like the Tomigotchi things with this? That would be awesome to see that as a Pet turtle.
WeeHeeHee #4
Posted 20 November 2012 - 08:14 PM
I love this code! But do you know what makes it better? Adding turtle.attack(); sleep(1) randomly and putting it in the machinery room :(/>/>
notyepenyar #5
Posted 16 December 2012 - 05:43 PM
looked away for less than a minute…
theoriginalbit #6
Posted 18 December 2012 - 12:24 AM
There is an error on line 52. You forgot to put spaces between turtle.getFuelLevel() and < and 100.

white space doesn't matter.
RunasSudo-AWOLindefinitely #7
Posted 27 December 2012 - 06:47 PM
There is an error on line 52. You forgot to put spaces between turtle.getFuelLevel() and < and 100.
There was an error in the entire thing. You have to replace newlines with spaces to conserve space and look more professional.

while true do if not abc then abc=true end f1return=function1(abc) abc=f1return if abc==17 or (abc==16 and dothing()) then abc=12 end return function1(nil) end
Dusty_Rebel #8
Posted 05 January 2013 - 05:39 PM
Looks Pretty Neat….
Moti #9
Posted 18 September 2013 - 04:58 PM
Cool code, I'm waiting for updates.
kreezxil #10
Posted 18 September 2013 - 05:59 PM
yeah it needs turtle attack in it. I think if it detects that is getting low on fuel it should enter panic mode and start digging looking for coal. Therefore 1 coal should always remain unused and it could use this loop to refuel itself:

turtle.select(1)
quantity=turtle.getItemCount(1)
if quantity > 1 then
  turtle.refuel(quantity-1) -- leave just one there, hopefully it is coal, that one is used for comparison when digging
end
for i=2,16 do
  turtle.select(i)
  turtle.refuel() -- atttempt to refuel off of entire stack
end
Lyqyd #11
Posted 18 September 2013 - 06:50 PM
Leave dead topic dead if there's nothing useful to add to them.