9 posts
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!
235 posts
Location
/dev/earth1aus5
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
9 posts
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.)
235 posts
Location
/dev/earth1aus5
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.
2088 posts
Location
South Africa
Posted 13 January 2013 - 02:02 PM
Hmm, try using os.pullEvent()?
Edit: Nevermind, forgot turtle.forward() yields :P/>
235 posts
Location
/dev/earth1aus5
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!
7508 posts
Location
Australia
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…
2088 posts
Location
South Africa
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
235 posts
Location
/dev/earth1aus5
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)
2088 posts
Location
South Africa
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/>
2447 posts
Posted 13 January 2013 - 02:49 PM
0.4s is exactly right. Each movement takes 8 MC ticks. Each MC tick is 0.05s.
9 posts
Posted 14 January 2013 - 02:40 AM
Thank you all so much!