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

Question- Turtle Speed

Started by gadget142, 13 January 2013 - 12:48 PM
gadget142 #1
Posted 13 January 2013 - 01:48 PM
Hello!
My question is simple.
What is the physical speed of a turtle?
Specifically, how many seconds does it take for a turtle to move forward, backward, up or down, one meter?
I'm asking because I am designing a sort of rescue turtle who can deliver food, etc. to other players in danger in SMP when no one is nearby and can help them. So if the turtle stays at home most of the time, and someone mining about 500 blocks away calls for help, I want to know how long it will take for the rescue turtle to reach them. (I'm assuming that the time for the computer to process "turtle.forward()" is insignificant.

Any help from the community would be greatly appreciated! Thank you!
RunasSudo-AWOLindefinitely #2
Posted 13 January 2013 - 01:49 PM
You could just make a turtle move, say, 15 blocks, and time how fast it takes.

EDIT

local time1 = os.clock()
for i = 1, 50 do
  turtle.forward()
end
local time2 = os.clock()
local tTime = time2 - time1

print("Turtle speed is " .. (tTime / 50) .. "s per block")
Edited on 13 January 2013 - 12:52 PM
gadget142 #3
Posted 13 January 2013 - 01:53 PM
You're right, of course, but I was wondering if anyone had a more specific number than could be acquired through empirical evidence, or if someone had already experimented.
(This might seem silly, but I don't have ComputerCraft right now- I play on an SMP that's currently in the process of being updated and so I don't have access to any features of the mod. Any questions I ask are from the perspective of someone who can't currently test or experiment in ComputerCraft.)
RunasSudo-AWOLindefinitely #4
Posted 13 January 2013 - 02:00 PM
There's nothing in the config, and I don't feel like decompiling everything and searching through the code, so experimentation might be your best bet.

Just make a Superflat world, change 50 to something really big like 500 and see what it comes up with.
remiX #5
Posted 13 January 2013 - 02:02 PM
Hmm, try using os.pullEvent()?

Edit: Nevermind, forgot turtle.forward() yields :P/>
RunasSudo-AWOLindefinitely #6
Posted 13 January 2013 - 02:07 PM
My test results
19.65 seconds for 50 blocks = 0.393 seconds / block
59.65 seconds for 150 blocks = 0.397 seconds / block

Accounting for small errors in this calculation, the speed looks to be 0.4s/block. Nice round number!
theoriginalbit #7
Posted 13 January 2013 - 02:08 PM
Accounting for small errors in this calculation, the speed looks to be 0.4s/block. Nice round number!
Same speed as a falling block then…
remiX #8
Posted 13 January 2013 - 02:16 PM
What did you use?

secs = 0
x = 10
timersleep = 0.1

function addSecs()
	t = os.startTimer(timersleep)
	while true do
		e, p1 = os.pullEvent("timer")
		if p1 == t then
			secs = secs + 1
			t = os.startTimer(timersleep)
		end
	end
end

function goForward()
	for i = 1, x do
		turtle.forward()
	end
end

parallel.waitForAny(addSecs, goForward)

print("Turtle took " .. secs/10 .. " seconds to go forward " .. x .. " times")

With that I get 3.6 seconds for 10 times and 19.2 seconds for 50 blocks forward
RunasSudo-AWOLindefinitely #9
Posted 13 January 2013 - 02:21 PM
What did you use?

secs = 0
x = 10
timersleep = 0.1

function addSecs()
	t = os.startTimer(timersleep)
	while true do
		e, p1 = os.pullEvent("timer")
		if p1 == t then
			secs = secs + 1
			t = os.startTimer(timersleep)
		end
	end
end

function goForward()
	for i = 1, x do
		turtle.forward()
	end
end

parallel.waitForAny(addSecs, goForward)

print("Turtle took " .. secs/10 .. " seconds to go forward " .. x .. " times")

With that I get 3.6 seconds for 10 times and 19.2 seconds for 50 blocks forward
Wow… That was…. overly complicated. Probably slightly more accurate than mine, but I don't know:

local time1 = os.clock()
for i = 1, 50 do
  turtle.forward()
  if (i % 10) == 0 then	 --This bit might add some time to the result...
    print(i .. " blocks")
  end
end
local time2 = os.clock()
print(time2 - time1)
remiX #10
Posted 13 January 2013 - 02:23 PM
Yeah, the first os.clock() you do, if you were to print time1, it'll probably print about 0.300 seconds or so. It's never 0 :P/>
Cloudy #11
Posted 13 January 2013 - 02:49 PM
0.4s is exactly right. Each movement takes 8 MC ticks. Each MC tick is 0.05s.
gadget142 #12
Posted 14 January 2013 - 02:40 AM
Thank you all so much!