You can find all of the ComputerCraft events and what they return
here.
os.startTimer is a function that will fire a
timer event when a certain amount of time has passed. With event it returns one parameter - unique ID for that timer. The same ID is returned when calling
os.startTimer:
local timer1 = os.startTimer(2) --// Start a timer to wait for 2 seconds
print("Timer 1 has started with ID of " .. timer1)
local timer2 = os.startTimer(1) --// Start a timer to wait for 1 second
print("Timer 2 has started with ID of " .. timer2)
local timer1Stopped = false
local timer2Stopped = false
--// We'll use these to stop the loop when both timers will stop
print()
while not timer1Stopped and not timer2Stopped do --// Run until both timers will have stopped
local event, timerID = os.pullEvent("timer")
if timerID == timer1 then
print("Timer 1 has stopped! ID: " .. timerID)
timer1Stopped = true
elseif timerID == timer2 then
print("Timer 2 has stopped! ID: " .. timerID)
timer2Stopped = true
end
end
--/* Output:
-- Timer 1 has started with ID of 6
-- Timer 2 has started with ID of 7
--
-- Timer 2 has stopped! ID: 7
-- Timer 1 has stopped! ID: 6
--*/
os.setAlarm is a function that when called will set an alarm that will fire
alarm event at a specified Minecraft in-game time. Like timers, with events it will return a unique ID which is returned when calling
os.setAlarm:
local alarm = os.setAlarm(7) --// Will set an alarm at 7 am
print("Alarm set at 7 am.")
repeat
local event, alarmID = os.pullEvent("alarm") --// Will wait for alarm event
until alarmID == alarm --// Checking if it is the alarm we want, it's the same thing like we did with timer ID
print("It's 7 am. Wake up!")
--/* Output:
-- Alarm set at 7 am.
-- It's 7 am. Wake up!
--*/
For your particular case you should use
os.clock.
os.clock returns a number in seconds about how long the computer is running (in-game ComputerCraft computer):
local ping = os.clock()
--// Do the rednet messages here
local pong = os.clock()
local timePassed = pong - ping
print("Time between ping and pong (in seconds) is " .. timePassed)
Edited by MKlegoman357, 15 December 2013 - 12:54 PM.