[Tutor] list question

proportional at msn.com proportional at msn.com
Tue Aug 11 14:17:15 CEST 2009


hi i am currently doing the 'livewires' python tutorial lesson 5. i am making a little game that makes a few squares chase a circle around a little grid. i can get the 1 square acting on 1 variable to come up, but the tutorial now wants me to create a list of variables that act under the same class.

this is what i have to make the 1 square appear (which works)(i have also cut a lot of the program out to make this email smaller.)

class Robot:
    pass

def place_robot():
    global robot    
    robot = Robot()
    robot.x=random_between(0,63)
    robot.y=random_between(0,47)
    draw_robot()
    print robot.x 

and i cant figure out what to write to make the variable 'robot' work as a list, and then follow all the instructions 3 times. this is what i tried to put in.

class Robot:
    pass

def place_robot():
    global robot
    r1 = Robot()
    r2 = Robot()
    r3 = Robot()
    robot = [r1,r2,r3]
    robot.x=random_between(0,63)
    robot.y=random_between(0,47)
    draw_robot()
    print robot.x 

i was under the assumption that the instruction robot.x=random_between(0,63) would return a value 3 times for r1 r2 and r3, but instead i get AttributeError: 'list' object has no attribute 'x'. so i got no idea heh. i hope this makes sense, as im really new to programming. thanks if anyone can help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090811/a97a48ba/attachment.htm>


More information about the Tutor mailing list