Thread: removeweapon()
View Single Post
  #10  
Old 07-10-2008, 02:23 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by DrakilorP2P View Post
Anyway, similar method, different language but guaranteed to work:
No it wouldn't.

If you want to delete stuff in an array part by part you need to start at the end so when you delete the element and the array shrinks in size you're not missing anything. When you're deleting a part from an array everything after it is decreasing in index so the for loop misses the element that replaced the one it just deleted while it moves on to the next highest index.

Also in your Python code the 'cruux' variable is unnecessary. You're taking the length from the 'foo' array and creating a new array from it but not actually using variable 'i', so you should just do for i in foo:

Edit:
Quote:
Originally Posted by DrakilorP2P
Just noticed my previous post is a really misleading way of deleting half the list.
It appears I was the one who was mislead when reading your post. Since I just noticed it was only deleting index 0 and not index i. If done like that it should work fine I guess.
__________________
Reply With Quote