It is called like so:
attack.horizontalAttack(100, 20, 10, 15) -- Just normally like attack.fire(turrets\_circle, target)
It is called like so:
attack.horizontalAttack(100, 20, 10, 15) -- Just normally like attack.fire(turrets\_circle, target)
Sorry having trouble reading the code. Reviewing again.
Now, this error appears:
ERROR: Runtime error error loading module 'attack' from file 'attack.lua': attack.lua:73: ')' expected near 'then' stack traceback: [C]: ? [C]: in function 'require' ?: in function 'require' main.lua:8: in main chunk
Oh, ok.
Dude, you can track down the typo right?
look at the code I posted then compare it to this.
if( not display.isValid( self ) ) then return end -- Extended function added by SSK2
Once you type that in, how is it working. OK? Any more errors?
I think I found the original source of your problem.
This is in the wrong order:
local function removeBlockades(self) display.remove(self) self:removeEventListener("enterFrame", self) -- WRONG NO MATTER WHAT end
Order of execution is CRITICAL. Should be:
local function removeBlockades(self) --self:removeEventListener("enterFrame", self) -- WRONG NO MATTER WHAT ignore( "enterFrame", self ) -- From SSK2 -- Equivalent to: Runtime:removeEventListener( "enterFrame", self ) display.remove(self) end
Key learnings:
Remove listeners, then delete.
‘enterFrame’ is a Runtime listener, not a table listener, you’re syntax made no sense. :wacko:
Use SSK2 ignore() and listen() intstead of longhand Runtime:* calls. ick!
One final post by me, this is how I would write the code w/ SSK2
(May contain typos)
local lifetime = 50000 local attack = {} function attack.horizontalAttack(blockadeNumber, spaceApart, speed, change) local function moveBlockades(self) if( autoIgnore( "enterFrame", self ) ) then return end if self.x + 15 \> 0 then self.x = self.x - speed end end local function removeBlockades(self) ignore("enterFrame", self) display.remove(self) end for i = 1, blockadeNumber do local blockadeBottom = ssk.display.newRect( nil, right + (i \* spaceApart), bottom, { w = 15, h = 200 + (i \* change), enterFrame = moveBlockades, anchorY = 1, fill = { 0.56, 0.13, 0.94 } }, { isSensor = true } ) local blockadeTop = ssk.display.newRect( nil, blockadeBottom.x, top, { w = 15, h = 200 - (i \* change), enterFrame = moveBlockades, anchorY = 0, fill = { 0.56, 0.13, 0.94 } }, { isSensor = true } ) blockadeTop.timer = removeBlockades timer.performWithDelay(lifetime, blockadeTop) blockadeBottom.timer = removeBlockades timer.performWithDelay(lifetime, blockadeBottom) end end return attack
Thank you, it works now.