Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-16-2011, 02:02 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 31
thyrgle is on a distinguished road
Default Deleting sprites causing problems in Corona SDK

I have an array called toRemove:

Code:
local toRemove = {}
I have a group called enemies which stores the enemy sprites and I have a collision detection function that looks like this:
Code:
local function onCollision( self, event )
    --Bullet hit enemy
    if self.name == "bullet" and event.other.name == "enemy" then
        table.insert(toRemove, event.other)
    end
end
It is getting inside the if statement. I have a game loop:

Code:
local function gameLoop ( event )

    for i = 1, #toRemove do
        toRemove[i].parent:remove(toRemove[i]) --This is line 158 (important to know later)
        toRemove[i] = nil
    end
end
This gameLoop function is invoked like so:

Code:
Runtime:addEventListener( "enterFrame", gameLoop )
When I run my program it says:

Code:
...main.lua:158: attempt to index field 'parent' (a nil value)
When I modify my game loop as follows:

Code:
local function gameLoop ( event )

    for i = 1, #toRemove do
        print(toRemove[i].parent)
        --toRemove[i].parent:remove(toRemove[i]) --This is line 158 (important to know later)
        toRemove[i] = nil
    end
end
Nothing crashes (although no sprite is removed), and it prints:

Code:
table: <memory Address>
Why wont it let me remove the parent?
thyrgle is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 413
11 members and 402 guests
AppleDev, chemistry, Emy, Gi-lo, ipodphone, mistergreen2011, pipposanta, Retouchable, skrew88, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,923
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:21 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0