Posted 13 September 2013 - 02:16 AM
So I was wondering what would be the best way of making a timer that can run while also waiting for other input. I do know of doing it in this way. Just an example.
user = "placeholder" -- this is only temp it get replaced using a different program. Only put it here so that there werent empty, random declarations
function timer()
sleep(10)
random = math.random(0,2)
if random == 0 then print("Random message 1")
elseif random == 1 then print("Random message 2")
elseif random == 2 then print("Random message 3")
end
end
local function check()
local event, player, message = os.pullEvent("chat")
if player == user then
local comStr = string.match(message, "^turtle:%s*(.*)")
if comStr then
for word in string.gmatch(message, "(%S+)") do
if commands[word] then
commands[word]()
end
end
end
end
end
while true do
parallel.waitForAny(check, timer)
end
--I do not have the array/table list here to go with the check(), but its in a different file, plus I mainly wondering about the timer portion.
Now I am 90% sure that this is the wrong way to go about doing a well designed timer, so what would you guys suggest I do instead. The main point for this code will to be a random message at random times while still being able to accept arguments from the user to run other functions.