【发布时间】:2013-12-02 06:03:22
【问题描述】:
function drag(event)
if event.phase == "began" then
firstx, firsty = event.x, event.y
end
if event.phase == "ended" then
if firsty<event.y then
local otherx, othery = event.x, event.y
local x=(otherx-firstx)*4
local y=(othery-firsty)*4
shoot(x,y)
end
end
end
event.phase 有问题?
程序将 firsty 与 event.y 进行比较时出错。
错误:尝试将 nil 与数字进行比较
奇怪的是,如果我只让程序加载几秒钟,它就可以完美运行..
【问题讨论】:
-
firsty在这种情况下进行比较之前没有被设置为nil以外的任何值,或者event.y有时是nil并覆盖firsty。 -
hmm.. firsty 好像是nil,但是如果在event.phase开始时(当我触摸屏幕时)声明它怎么可能是nil
-
firsty声明在哪里?它不会在程序的其他任何地方使用,是吗?