python - Moving objects as a list -
so in below code trying give menu of instructions. having problems 'n' command section calls maketurtle() function. trying add turtles list (children []) when iterate through list makes turtles move @ same time. problem can 1 turtle move (the first 1 create). able them move, stop working if made new one. can help?
home = makeworld() children = [] def maketurtle(): newborn = maketurtle(home) children.append(newborn) return newborn def roamingturtles(): command = raw_input("---> ") if command == 'n': maketurtle() roamingturtles() if command == 'r': in children: i.turn(90) roamingturtles() if command == 'l': in children: i.turn(-90) roamingturtles() if command == 'm': in children: i.forward() roamingturtles() if command == 'q': print 'end'
your issue appears you're not waiting until loop on children completes before recalling roamingturtle
function. why 1 of turtles updates. example, have:
for in children: i.forward() roamingturtles()
but instead, want:
for in children: i.forward() roamingturtles()
Comments
Post a Comment