I am ultimately making a timer that fires at random intervals. (between ~2 and ~7 seconds)
My code is successful, but requires a “steady” timer to call a “random timer”.
Any thoughts on making it more efficient/less sloppy?
Thanks,
Dane
[lua]local cratespinning = 0
local function crateanimationfunction() --makes the crates spin
if #pulleycratespawns > 0 then
math.randomseed( os.time() )
local randnum = math.random(#pulleycratespawns)
pulleycratespawns[randnum]:prepare(“crateanimation”)
pulleycratespawns[randnum]:play(“crateanimation”)
end
cratespinning = 0
end
local function cratespinner() --waits for a crate to stop spinning
if cratespinning == 0 then
cratespinning = 1
math.randomseed( os.time() )
print(math.random(1,3))
local cratespinningtimer = timer.performWithDelay(2500*math.random(1,3), crateanimationfunction, 1) --makes random intervals
end
end
math.randomseed( os.time() )
local cratetimer = timer.performWithDelay(1000, cratespinner, 0) --regularly calls random timer function[/lua]
[import]uid: 117490 topic_id: 22453 reply_id: 322453[/import]