This is the code I use to remove the gun from the contents list. But when it does this my contents.len does not update and shows that the object is still in the list. Is there anyway I can get the contents.len to update when the src deletes itself?
obj/guns
verb/Stock()
M.crewguns++
del src
ID:147895
![]() Oct 10 2003, 9:38 am
|
|
Malver wrote:
Perhaps the problem lies elsewhere in the code, or you've made somesort of logic error? The problem is not with the current code. But what happens to contents.len when the object deletes itself. To note: I've also tried contents.len -= 1 which deletes an item and the del src deletes another. But if I just allow the above code to take it's course. the contents.len does not update itself. For example: Total guns = 2 / 6 2 = [contents.len] 6 = listmax_limit // preset var If I let the object del src, it removes the item from the list, but contents.len does not update so I get the following: Total guns = 2 / 6 But the item is no longer there. |
But the item is no longer there. No but null is there and that counts. I remember LummoxJR pointing out a simple way to cull the nulls but I don't remember it off hand :P. |
I don't know what the heck the problem was with this code. I'm still baffeled!! But I just decided to forget contents.len and made my own .len function that works fine!
LJR |
I don't know what the heck the problem was with this code. I'm still baffeled!! But I just decided to forget contents.len and made my own .len function that works fine! When you delete an object all references to it become null. So if there was a list reference to it it also becomes null. The null list item is still counted in your length which is why you're having the problem you are having. Just do
while(contents.Remove(null));
whenever you want to clear them out. |
Theodis wrote:
But the item is no longer there. In an ordinary list this would be the case, but in a contents list I believe the item should be removed automatically, leaving no null. Still, the easy solution would be to set loc=null before deleting the item. Lummox JR |
This code works flawlessly for me (minus the 'M.crewguns++').
Perhaps the problem lies elsewhere in the code, or you've made somesort of logic error?