Hey there,
I have created a function which starts with a table that should spawn an object with a random image.
Then after that it gets on the players screen and moves towards the middle of the screen.
That worked out but now i want to use tables in order to be able to spawn multiple objects and to be able to delete all these objects when leaving the scene. But my function doesnt work and i have been tinkering with it for a while.
I have been using another thread as the example but somehow applying it doesnt work out for me… please help me out!
Example: http://forums.coronalabs.com/topic/50141-group-removal-multiple-twin-objects/
My code:
function spawnEnemy() enemytable = {} local enemypics = {"images/beetleship.png","images/octopus.png", "images/rocketship.png"} enemypic = enemypics[math.random(#enemypics)] local enemies = display.newGroup() for i=1,5 do enemytable[i] = display.newImage(enemypic) enemies:insert(enemytable[i]) enemytable[i]:addEventListener ( "tap", shipSmash ) end if math.random(2) == 1 then enemytable[i].x = math.random ( -100, -10 ) else enemytable[i].x = math.random ( display.contentWidth + 10, display.contentWidth + 100 ) enemytable[i].xScale = -1 end enemytable[i].y = math.random (display.contentHeight) enemytable[i].trans = transition.to ( enemytable[i], { x=centerX, y=centerY, time=math.random(2500-speedBump, 4500-speedBump), onComplete=hitPlanet } ) speedBump = speedBump + 50 end
The error i am receiving is attempting to index field “?” ( a nil value)
Please help me out!
Regards,