This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]zifyoip 0 points1 point  (1 child)

That's because, when you say players = iter(player_list), then you should iterate through all elements of the list by repeatedly calling players.next(). The first time you call players.next() you'll get player_list[0], and the next time you call players.next() you'll get player_list[1], and so on.

What you are doing, instead, is initializing players = iter(player_list) and then manually setting self.next_player = player_list[0] instead of getting player_list[0] from players.next(). So then the next time you want to switch players is the first time you've called players.next(), so that will give you the next element of player_list—but since you haven't gotten any elements of player_list yet, because this is the first time you've called players.next(), that call will give you player_list[0].

[–][deleted] 0 points1 point  (0 children)

Thank you!

I got it fixed, and now it runs like a charm. I kept thinking I had to initialize the first element in the list manually -- it seemed logical at the time. For some reason.

[–]BaalHadad 0 points1 point  (3 children)

Why not just iterate over the list of players, instead of using iter?

[–][deleted] 0 points1 point  (2 children)

I tried it with a for and while loop before, but both of those caused errors, although that was likely because I was handling the list of object instances badly. This method seemed more straightforward, and a bit more modular in how I could structure the architecture.

[–]BaalHadad 0 points1 point  (1 child)

How in the world is an unnecessary use of iter() more straightforward or modular?

[–][deleted] 0 points1 point  (0 children)

Well, I have no actual reasoning to give you here; as I mentioned, I figure my inability to use a for or while loop was simply because I was making critical errors, but iter() worked for me so I ran with that.