更新performWithDelay math.random的值

时间:2013-06-19 20:28:40

标签: lua corona

我怎样才能每秒更新math.random的值?

tmrSpawn = timer.performWithDelay(math.random(9, 50), spawnBC3, 0)

它在9/50之间选择1(并保持该值)但我希望它每次刷新此值,任何想法如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您应修改 spawnBC3 功能:

local function spawnBC3()

    -- your code here

    if(tmrSpawn == nil) then
        tmrSpawn = timer.performWithDelay(math.random(9, 50), spawnBC3)
    else
        timer.cancel( tmrSpawn )
    end
end

--here we start the timer first time
local tmrSpawn = timer.performWithDelay(math.random(9, 50), spawnBC3)