[Tutor] Livewires - stuck on a class
Tonu Mikk
tmikk at umn.edu
Wed Aug 15 19:19:54 CEST 2007
Alan Gauld wrote:
> "Tonu Mikk" <tmikk at umn.edu> wrote
>
>
>> I create more robots in this way which seems to work:
>> class Robot:
>> pass
>>
>
> By using an empty class you are losing m,uch of the power of classes.
>
>
I would need to learn more to handle the classes better. In this case,
I am following the Livewires tutorial pretty closely which uses an empty
class.
>> def move_robot():
>> for x in robots:
>> while 1:
>> if robot.x + 0.5< player.x and robot.y +0.5< player.y:
>>
>
> You are doing *for x in robots* but then moving *robot* not x.
>
Yes, that was my mistake. I changed the line to "for robot in robots:"
and now it works!
>
> Also it would be better IMHO to use if/elif rather than all those
> if/breaks.
>
I followed your advice here. It does make the code a bit more clear.
Thanks a lot,
Tonu
More information about the Tutor
mailing list