Khi tôi tạo hàm bằng cách gán, điều kiện "nếu" không hoạt động nhưng khi tôi tạo chức năng như trong ví dụ thứ hai bên dưới, nó hoạt động. Bạn có thể cho tôi biết tại sao?Chức năng tạo trong Lua
Không làm việc:
local start=os.time()
local countDown = function(event)
if((os.time()-start)==3) then
Runtime: removeEventListener("enterFrame", countDown)
end
print(os.time()-start)
end
Runtime:addEventListener("enterFrame", countDown)
làm việc:
local start=os.time()
local function countDown(event)
if((os.time()-start)==3) then
Runtime: removeEventListener("enterFrame", countDown)
end
print(os.time()-start)
end
Runtime:addEventListener("enterFrame", countDown)