help with listremove()
BlitzMax Forums/BlitzMax Beginners Area/help with listremove()
| ||
i have a type called Sprite and a list called spritelist that has a number of sprite types stored in it, i want to remove 1 from the list so i try listremove (spritelist, bob) (bob is a sprite in the list as in bob:sprite=a member of the sprite list) and i cant get it to work and ideas ? thanks Ian |
| ||
Have you got any code? What doesn't'work? What errors do you get? Is the list global to Sprite? There are so many ways to do this. Here is something that works... Type sprite Global spritelist:TList=CreateList() Field x End Type bob:Sprite = New sprite bob.x = 5 ListAddLast(sprite.spritelist , bob) Print CountList(sprite.spritelist) ListRemove(sprite.spritelist , bob) Print CountList(sprite.spritelist) or a simpler example... Type sprite Field x End Type Global spritelist:TList=CreateList() bob:Sprite = New sprite bob.x = 5 ListAddLast(spritelist , bob) Print CountList(spritelist) ListRemove(spritelist , bob) Print CountList(spritelist) |
| ||
I've got into the habit now of keeping the TLink that is returned when you add an object to a TList. Then you can just call the Remove() method of that TLink. EG: Type sprite Global List:TList Field x:Int,y:Int Field Link:TLink Method New() If List=Null List=New TList End If Link=List.AddLast(Self) End Method Method Kill() Link.Remove() Link=Null End Method End Type bob:Sprite = New sprite Print CountList(sprite.list) bob.Kill() Print CountList(sprite.list) |