It appears that what I’m about to post has posed a problem to many (for example, a variation of it appears here:http://developer.anscamobile.com/forum/2010/09/06/problem-removeself-when-adding-bodys-table). Here’s the code:
--import the ; class for sharper text
local retina = require("retina");
--Create table to hold missiles
local silo = {}
--Index for the silo table
local ndx = 0;
--spawn missiles on command
function spawnMissiles()
ndx = ndx + 1;
--Create a single instance of a missile (to be assigned to multiple table entries later
--This is a custom method that loads newImageRect's)
silo[ndx] = retina.newImage({image="images/missile.png",width=70,height=36,origin="center-right"});
silo[ndx].x = -80; silo[ndx].y = display.contentHeight/2;
transition.to(silo[ndx], {time=1500, x=500, onComplete=removeMissiles});
end
--remove missiles if they cross the left-half of the screen
function removeMissiles()
for i = 1, #silo do
local s = silo[i]
if (s.x) then
print(s.x)
if (s.x \> \_W/2) then
s:removeSelf();
end
end
end
end
--spawn 10 missiles
spwnr = timer.performWithDelay(500, spawnMissiles, 10);
and here’s the error (the stated line number and line number show above match):
Runtime error
...ts/iPhoneDev/Corona Projects/MissilePhysics/main.lua:26: attempt to perform arithmetic on global '\_W' (a nil value)
stack traceback:
[C]: ?
...ts/iPhoneDev/Corona Projects/MissilePhysics/main.lua:26: in function <...ts projects><br> (tail call): ?<br> ?: in function <?:866><br> ?: in function <?:214><br>
My guess is that the error has something to do with trying to get rid of the object in the silo table before transition.to is done with it. But, that’s just a guess. The folks on the board are quite generous with their time and I certainly do appreciate any responses that help shed light on what in the logic is causing this foul up. [import]uid: 13345 topic_id: 4753 reply_id: 304753[/import] </…ts>