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碰撞零值_Lua_Physics_Collision_Null - Fatal编程技术网

Lua碰撞零值

Lua碰撞零值,lua,physics,collision,null,Lua,Physics,Collision,Null,当我试图执行以下代码时,它给出了以下错误: 尝试索引字段“其他”(零值) 但我不知道为什么 守则: function onCollision(event) if event.phase == "began" then if event.other.star == "star" then score = score + 1 elseif event.other.mine1 == "mine1" then if jet.collided == fals

当我试图执行以下代码时,它给出了以下错误:

尝试索引字段“其他”(零值)

但我不知道为什么

守则:

function onCollision(event)
 if event.phase == "began" then 
    if event.other.star == "star" then
       score = score + 1
    elseif event.other.mine1 == "mine1" then
       if jet.collided == false then
         timer.cancel(tmr)    
         jet.collided = true    
         jet.bodyType = "static"
         explode()
       end
     end
   end
 end

提前感谢:)

正如@lhf和@RBerteig所说的问题是
事件。其他
nil
,因此尝试访问
star
成员无法尝试索引nil值

假设
event.other
确实可以是
nil
,解决问题的惯用方法是在前面的if
if event.phase==“start”和event.other then
,因为if和else条件都取决于要设置的
event.other

function onCollision(event)
 if event.phase == "began" and event.other then 
    if event.other.star == "star" then
       score = score + 1
    elseif event.other.mine1 == "mine1" then
       if jet.collided == false then
         timer.cancel(tmr)    
         jet.collided = true    
         jet.bodyType = "static"
         explode()
       end
    end
  end
 end

如果您想知道“尝试索引字段”的消息,您也可以阅读更多关于的信息,因为@lhf和@RBerteig说问题是
事件。其他
nil
,因此尝试访问
star
成员无法尝试索引nil值

假设
event.other
确实可以是
nil
,解决问题的惯用方法是在前面的if
if event.phase==“start”和event.other then
,因为if和else条件都取决于要设置的
event.other

function onCollision(event)
 if event.phase == "began" and event.other then 
    if event.other.star == "star" then
       score = score + 1
    elseif event.other.mine1 == "mine1" then
       if jet.collided == false then
         timer.cancel(tmr)    
         jet.collided = true    
         jet.bodyType = "static"
         explode()
       end
    end
  end
 end

如果您想知道“尝试索引字段”的消息,您也可以阅读更多关于的信息,这意味着
事件。其他
为零。lhf所说的。这意味着传递给
onCollision
的值是一个表(或类似于表的庸医),但它没有名为
other
的字段。也许该字段实际上被命名为
Other
。也许
onCollision
没有传递您认为它已经传递的对象。这意味着
event.other
为零。lhf所说的。这意味着传递给
onCollision
的值是一个表(或类似于表的庸医),但它没有名为
other
的字段。也许该字段实际上被命名为
Other
。可能
onCollision
没有传递您认为它已经传递的对象。