1
J'apprends la langue Lua. Je suis un peu confuse. Je souhaite passer l'argument à la fonction timer.PerformWithDelay. Voici le code que j'ai écrit:Passer des arguments à travers timer.PerformWithDelay - Lua
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
Ma question est: pourquoi la variable RTAM ne passe pas à la fonction reverseRotation?
'fonction reverseRotate (RTAM) si RTAM> 0 ...' et 'function() reverseRotate (RTAM) end' –
Bien sûr, j'oublié d'ajouter RTAM en rond parenthèses ... Également réécrit des guillemets de docs: D Silly meeeee. Merci Egor! – Neru
@EgorSkriptunoff s'il vous plaît poster votre commentaire dans la section des réponses. Neru, s'il vous plaît accepter sa réponse une fois qu'il est là. –