2013-10-05 35 views
0

我試圖用計時器更改變量值時報告了問題。無法通過計時器更改值

其實我用下面的代碼來執行:

local counter = math.random(100, 350) 
local function changeCounterValue() 
    counter = math.random(130, 170) 
end 
tmr = timer.performWithDelay(1500, changeCounterValue, 0) 

,但它只是不工作?

+0

什麼這讓與Android呢? –

+0

Corona以Android和iOS爲目標,但這顯然是一個獨立於目標平臺的Corona/Lua問題。 – acj

+2

對不起,我正在使用CORONA SDK開發我的應用程序 – luaLover

回答

-1

當您使用計時器時,您正在更改變量的範圍。所以用你的計時器,你正在創建另一個計數器變量,而不是更新值。你應該做的是這樣的:

test.lua:

counter = math.random(100, 350) 

local function changeCounterValue() 
    test.counter = math.random(130, 170) 
end 

tmr = timer.performWithDelay(1500, changeCounterValue, 0) 
+0

非常感謝,它終於正常工作! :) – luaLover