我正在学习Lua语言。我有点困惑。我想通过 timer.PerformWithDelay 方法将参数传递给函数。这是我写的代码:
local function animate ( event )
gear.rotation = gear.rotation + rotateAmount;
end
Runtime:addEventListener("enterFrame", animate);
------------------------------------------------
function reverseRotate()
if tonumber(rtAm) > 0 then -- here appear error: "Attempt to compare number with nil"
rotateAmount = rotateAmount - 1;
elseif tonumber(rtAm) < 0 then
rotateAmount = rotateAmount + 1;
end
end
------------------------------------------------
local buttonHandler = function ( event )
if event.phase == "ended" then
local iteration = math.abs(rotateAmount);
if rotateAmount > 0 then
local rtAm = rotateAmount;
timer.performWithDelay(100, function() reverseRotate ("rtAm") end, 2*iteration);
elseif rotateAmount < 0 then
local rtAm = rotateAmount;
timer.performWithDelay(100, function() reverseRotate ("rtAm") end, 2*iteration);
end
end
end
所以我的问题是:为什么变量 rtAm 没有传递给 reverseRotation 函数?