Problems with a function for a newly-created object, previously not in screen

and once you’ve done this as per @nick_sherman, you might realize that you probably don’t need separate wrapShip and wrapLaser functions, just one “wrapGenericThingy” function with a reference to that thingy.

@nick_sherman and @davebollinger,

Dang, this is exactly what the Star Explorer demo does; I just didn’t realize it.  The collision function uses an if statement, thus if no asteroid is there, no prob, right?  You REM line “gameLoopTimer = timer.performWithDelay( 500, gameLoop, 0 )” to validate the game does not crash, and surely enough, it doesn’t.

I guess it was a long week at work.  Let’s get to rewriting the code then.

Thanks for the advice to all who replied!

Solved!

The solution to fire multiple lasers and each follow their own path wrapping the screen was to not treat the lasers as a collision with a bumper, but rather place the x,y logic within the gameLoop:

 for i = #laserTable, 1, -1 do local thisLaser = laserTable[i] if (thisLaser.x \> display.contentWidth + (fudgeNum \* .5)) then thisLaser.x = -(fudgeNum \* .5) else if (thisLaser.x \< -(fudgeNum \* .5)) then thisLaser.x = display.contentWidth + (fudgeNum \* .5) else if (thisLaser.y \< -(fudgeNum \* .5)) then thisLaser.y = display.contentHeight + (fudgeNum \* .5) else if (thisLaser.y \> display.contentHeight + (fudgeNum \* .5)) then thisLaser.y = -(fudgeNum \* .5) end end end end end

Please pardon the tabs if the code is out of tab above.  You will notice that the lasers are tracked via a table.  That way they all go about their own direction.  All that’s left is to destroy the stray laser after about a second or so if it does not collide with an asteroid or an enemy craft.

Thanks much to all of you who nudged me in the right rotation (direction!).