简体   繁体   English

尝试将nil与电晕数字进行比较

[英]attempt to compare nil with number Corona

I'm about to finish my game, but I ran into an error: 我即将结束比赛,但遇到错误:

attempt to compare nil with number game2.lua 444

I don't have a clue on how to fix this, and I've tried quite everything, with no success. 我对如何解决这个问题一无所知,而且我已经做了很多尝试,但都没有成功。 I think the function scrollSpace is causing this, because sometimes the background would scroll at an uncontrollable speed. 我认为函数scrollSpace导致了这种情况,因为有时背景会以无法控制的速度滚动。 Here is my code: 这是我的代码:

function scrollSpace(self,event)
    if self.x  < -900 then
        self.x = 800
    else 
        self.x = self.x - self.speed
    end 
end

This controls how the stuff scroll across the screen. 这控制了东西如何在屏幕上滚动。 If you guys what more code, just reply, and I'll be happy to add the requested source. 如果您还有更多代码,请回复,我们很乐意添加所请求的源。 One last thing: does anyone know what the following error means: 最后一件事:有谁知道以下错误是什么意思:

attempt to compare nil with number

this is my file code: 这是我的文件代码:

  coin01 = display.newImage("coin02.png")
  coin01.y = 100
  coin01.x = 500
  coin01.speed = math.random(2,6)
  coin01.initY = mine1.y
  coin01.amp   = math.random(20,100)
  coin01.angle = math.random(1,360) 

 physics.addBody(coin01, "static", {density=.1,bounce=0.1, friction=.2,radius=12})
 screenGroup:insert(coin01)
 end  -- end of create scene
**print "passed"

 function scrollSpace(self,event)
 if self.x  < -900 then
  self.x = 800
else 
self.x = self.x - self.speed
 end 
    end**
function scene:enterScene(event)

coin01.enterFrame = coins
Runtime:addEventListener ("enterFrame",coin01)  
  end 
  function scene:exitScene(event)
 ***storyboard . purgeScene ("start")
 story board . purgeScene ("restart")***
  Runtime:removeEventListener ("enterFrame",coin01)

  end

   function scene:destroyScene(event)

end

scene:addEventListener("createScene",scene)
scene:addEventListener("enterScene",scene) 
scene:addEventListener("exitScene",scene) 
scene:addEventListener("destroyScene",scene) 

return scene

Apperantly self.x is a nil value.. If you remove it somewhere and then listener is called in the same time, there wont be any self.x value. 显然self.x是一个nil值。如果将其删除,然后在同一时间调用监听器,则不会有任何self.x值。

You should post every line where you change/create self object. 您应该在更改/创建自我对象的每一行中发布。 And also listener 还有听众

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM