Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 若对象传递y值,则调用函数_Lua_Coronasdk - Fatal编程技术网

Lua 若对象传递y值,则调用函数

Lua 若对象传递y值,则调用函数,lua,coronasdk,Lua,Coronasdk,我有一个对象正在逐步向下移动,我希望在对象通过某个Y轴时调用触摸功能 所以我有一个if条件来检查square.y是否大于150。如果该条件为真,我希望能够调用触摸功能 我该怎么做 我试过这样做,但不起作用 if (square.y > 150) then function square:touch (event) // do something end end 您定义了函数square:touch,但没有调用它。您需要使用square:to

我有一个对象正在逐步向下移动,我希望在对象通过某个Y轴时调用触摸功能

所以我有一个if条件来检查square.y是否大于150。如果该条件为真,我希望能够调用触摸功能

我该怎么做

我试过这样做,但不起作用

 if (square.y > 150)  then
    function square:touch (event) 
            // do something
    end
 end

您定义了函数
square:touch
,但没有调用它。您需要使用
square:touch()调用它。

如果需要,还可以在
if
语句之外定义函数,以使其更清晰:

function square:touch (event) 
   print("calling touch")
end

if square.y > 150  then
    square:touch()
end

非常感谢你!这很有帮助。如果我这样做,然后我把方块拖到y小于150的地方,方块会冻结,对吗?这是好事吗?我怎么能改变呢?@Glund我没法帮你,因为我从来没用过电晕。很公平。非常感谢。
function square:touch (event) 
   print("calling touch")
end

if square.y > 150  then
    square:touch()
end