[英]Attempt to compare nil with number on (i).x < 100 then
我正在嘗試生成一個新的display.newRect如果到舊的顯示是<100,但是我得到一個“試圖將nil與數字進行比較”
function hollSpawne(i)
if (i).x < 100 then
hollspawn()
end
end
HollControll = timer.performWithDelay( 1400 , hollSpawne, 0 )
我看不到錯誤,有人可以解釋一下解決方法嗎?
完整代碼:
function pluspoint(i)
score = score + 1
display.remove(i)
end
screenGroup = self.view
holl = {}
hollSpawn = function()
i = display.newRect( 0, 0, math.random(10, 500), 53 )
i.x = display.contentWidth + i.contentWidth + 10
i.y = display.contentHeight - 53/2
i:setFillColor( 1, 0, 0 )
i.name = "hollgameover"
physics.addBody(i, "static", {density=.1, bounce=0.5, friction=.2,filter=playerCollisionFilter } )
trans55 = transition.to(i,{time=2000, x=display.contentWidth - display.contentWidth - i.contentWidth/2 - 20, onComplete=pluspoint, transition=easing.OutExpo } )
holl[#holl+1] = i
screenGroup:insert(i)
end
timereholl = timer.performWithDelay( 100 , hollSpawn, 1 )
function hollSpawne(i)
if (i).x < 100 then
hollspawn()
end
end
HollControll = timer.performWithDelay( 1400 , hollSpawne, 0 )
新測試仍然無法正常工作
screenGroup = self.view
holl = {}
hollSpawn = function()
i = display.newRect( 0, 0, math.random(10, 500), 53 )
i.x = display.contentWidth + i.contentWidth + 10
i.y = display.contentHeight - 53/2
i:setFillColor( 1, 0, 0 )
i.name = "hollgameover"
physics.addBody(i, "static", {density=.1, bounce=0.5, friction=.2,filter=playerCollisionFilter } )
trans55 = transition.to(i,{time=2000, x=display.contentWidth - display.contentWidth - i.contentWidth/2 - 20, onComplete=pluspoint, transition=easing.OutExpo } )
holl[#holl+1] = i
screenGroup:insert(i)
end
timereholl = timer.performWithDelay( 100 , hollSpawn, 1 )
function hollSpawne(event)
if (i).x < 100 then
hollSpawn()
end
end
HollControll = timer.performWithDelay( 1400 , hollSpawne, 0 )
您的計時器不帶任何參數調用hollSpawne,但在函數中使用“ i”參數。 試試這個:
local function hollSpawne(i)
if i.x < 100 then
hollspawn()
end
end
HollControll = timer.performWithDelay( 1400 , function()
hollSpawne(my_i_value)
end, 0 )
計時器使用事件作為參數調用偵聽器,因此我是一個事件。 由於我是一個全球性人士,因此您可以使用arg be事件:
function hollSpawne(event)
if (i).x < 100 then
hollSpawn()
end
end
請注意,我使用的不是hollspawn
,而是我使用的hollSpawn
因為我認為這是一個錯字,會導致其他錯誤。
風格的旁注:不確定為什么需要在()
i
()
地方使用()
。 另外,您可能應該在模塊本地聲明i
:
local i
screenGroup = self.view
holl = {}
hollSpawn = function()
i = display.newRect( 0, 0, math.random(10, 500), 53 )
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.