Deleting objects / references in lists
BlitzMax Forums/BlitzMax Beginners Area/Deleting objects / references in lists
| ||
I have a type called foodPellet, and a Tlist of 400 of them. They need to be able to delete themselves from the list, but I don't know how to do that. I created the list like this: Global foodlist:TList = CreateList() For i = 0 To 400 ListAddLast(foodlist, foodpellet.create(Rand(1,4), width/2 + Rand(-1500,1500), height/2 + Rand(-1500,1500), gameGraphics)) Next Individual foodpellets know when its time for them to be deleted, and I run through the list updating them all, so they can call a deleteme() method inside them, but I dont know how to delete them from the list, or even how to make them know what member of the list they are. I think it may be related to something else I dont know how to do: From an instance of a type, getting the instance, like, getting a var to be itself. Thanks in advance, Will. |
| ||
Did you look up "listremove" ? For instance if I have: global foodlist:TList = createlist() for i = 0 to 400 f:food = new food listaddlast foodlist,(f) if keyhit(KEY_SPACE) listremove foodlist,(f) The above wont compile obvisouly and has missing bits but it shows how to remove an object from a list. Hope that helps. |
| ||
how to make them know what member of the list they are When called from within a Method, the object in question is always "self". |
| ||
oh, thanks, combining those two should make it work great - thanks! |