试图用一些比较电晕为零 [英] attempt to compare nil with number Corona
问题描述
我要完成我的比赛,但我遇到了一个错误:
尝试比较比零号game2.lua 444
我没有关于如何解决此问题的线索,我已经尝试过的所有内容,但没有成功。我认为功能 scrollSpace
是导致此,因为有时后台会滚动以无法控制的速度。这是我的code:
函数scrollSpace(个体经营,事件)
如果self.x< -900那么
self.x = 800
其他
self.x = self.x - self.speed
结束
结束
本控制如何在屏幕上滚动的东西。如果你们有什么更多的code,只需回复,我会很高兴的添加请求的来源。最后一件事:没有人知道下面的错误方式:
尝试比较比零号
这是我的文件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(20100)
coin01.angle =的Math.random(1,360)
physics.addBody(coin01,静,{密度= 0.1,反弹= 0.1,摩擦= 2,半径= 12})
screenGroup:插入(coin01)
结束 - 创建场景结束
**打印合格
功能scrollSpace(个体经营,事件)
如果self.x< -900那么
self.x = 800
其他
self.x = self.x - self.speed
结束
结束**
功能情景:enterScene(事件)
coin01.enterFrame =硬币
运行时间:调用addEventListener(一个enterFrame,coin01)
结束
功能情景:exitScene(事件)
***故事情节。 purgeScene(开始)
故事板。 purgeScene(重启)***
运行时间:removeEventListener(一个enterFrame,coin01)
结束
功能情景:destroyScene(事件)
结束
场景:的addEventListener(createScene,场景)
场景:的addEventListener(enterScene,场景)
场景:的addEventListener(exitScene,场景)
场景:的addEventListener(destroyScene,场景)
返回现场
Apperantly self.x是一个零值。如果你删除它的地方,然后监听器被调用的同时,也不会是任何self.x值。
您应该张贴每一个地方你改变/创建自对象行。而且还监听器
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. 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.
You should post every line where you change/create self object. And also listener
这篇关于试图用一些比较电晕为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!