Attempt to compare nil with number on (i).x < 100 then

I am trying to spawn a new display.newRect if to old one is < 100 but I’m getting a ‘Attempt to compare nil with number’

function hollSpawne(i) if (i).x \< 100 then hollspawn() end end HollControll = timer.performWithDelay( 1400 , hollSpawne, 0 ) &nbsp;

I cant see the error, could someone please explain how to fix this ?

Fullcode :

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 ) &nbsp;

‘i’.x  is  nil  because ‘i’ is the event passed to the function, not the i newRect.

try changing the ‘i’ inside the function definition to ‘event’

function hollSpawne(event) if (i).x \< 100 then hollspawn() end end

Hi Renato the error is not oping up anymore but its not doing the “hollspawn()”

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 ) &nbsp;

‘i’.x  is  nil  because ‘i’ is the event passed to the function, not the i newRect.

try changing the ‘i’ inside the function definition to ‘event’

function hollSpawne(event) if (i).x \< 100 then hollspawn() end end

Hi Renato the error is not oping up anymore but its not doing the “hollspawn()”

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 ) &nbsp;