[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Re: collidelist Problem, indices



In a message of Wed, 22 Aug 2007 09:10:07 PDT, "Ian Mallett" writes:
>------=_Part_77788_14720920.1187799007217
>Content-Type: text/plain; charset=ISO-8859-1
>Content-Transfer-Encoding: 7bit
>Content-Disposition: inline
>
>On 8/20/07, C. Schildt <c.schildt@xxxxxx> wrote:
>>
>> Ian Mallett <geometrian@...> writes:
>>
>> >
>> > Well, your index must be an integer, but that wouldn't cause that
>> error...But
>> aside from that, an index too large is the only thing that causes that
>> problem.
>> Could you at least try it?Ian
>>
>>
>> Well if i do so, every strange effect stops, but, the wrong dogfighter
>> explodes
>> and the crashing dogfighter do not get an reset, So that DF1 crachses, 
>DF2
>> explodes, DF2 explodes..DF2 explodes etc
>
>
>Well, then the problem is somewhere else.  The only thing that causes an
>index out of range error is something too big.
>Best of luck!
>Ian

Too small can get you as well:
>>> v=[1,2,3,4]
>>> for i in range(0, -15, -1):
...     print i, v[i]
...
0 1
-1 4
-2 3
-3 2
-4 1
-5
Traceback (most recent call last):
  File "<stdin>", line 2, in ?
IndexError: list index out of range

---
but from what you are discribing, I fear that your problem may be
that you are modifying the list  you are interating over.  All sorts
of weird things can happen when you do that.  Sometimes you can fix
that by just making a copy of the list and iterating over that, but
sometimes you have to do the game logic differently.

so if the logic boils down to:

for i in planes:
    whats_happening(planes[i])

and when planes[3] blows up it also destroys planes[4] and planes[7] 
if you are not careful your list of planes will shrink but your
loop is still running on the old size.

Laura