Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Pilot Lvl 1
Message 1 of 2

I can't break out of the while loop!

Hi!

 

I'm working on a game, and so I got up to the part where a message comes up, but it keeps repeating the message. I tried break, searched it up, and tried this answer, but it didn't work. This is the gist link.

 

So I need help to break out of the loop, once it printed the message.

 

while True:

    for treasure in treasures:
        if player.is_collision(treasure):
            player.gold += treasure.gold
            treasure.destroy()
            treasures.remove(treasure)

            if player.gold == 100:
                print("100 Gold Pieces")

    for enemy in enemies:
        if player.is_collision(enemy):
            wb.open('https://cookibytes.github.io/GameSites/quest/error')
            sys.exit()

    wn.update()

    for friend in friends:
        if player.is_collision(friend):
            instruction = """
            - INCOMING MESSAGE -
            *********************

            Hey there! I'm Luz Lilac, your instructor and friend in this game. As
            you use the Up, Down, Left and Right arrow keys to move, you are
            equipped with bombs. 

            To whichever direction to fire, you use the W, A,
            S, D keys. Get the treasure chests, go to any openings you can find, and
            either avoid or shoot those Yeti. Literallly run to me for clues / help!
            """
            print(instruction)
            break

    turtle.ontimer(bullet.move, t=1)
Problem is here:
for friend in friends:
        if player.is_collision(friend):
            instruction = """
            - INCOMING MESSAGE -
            *********************

            Hey there! I'm Luz Lilac, your instructor and friend in this game. As
            you use the Up, Down, Left and Right arrow keys to move, you are
            equipped with bombs. 

            To whichever direction to fire, you use the W, A,
            S, D keys. Get the treasure chests, go to any openings you can find, and
            either avoid or shoot those Yeti. Literallly run to me for clues / help!
            """
            print(instruction)
            break

    turtle.ontimer(bullet.move, t=1)
 

 

Help is very much appreciated,

- CookiBytes

1 Reply
Highlighted
Pilot Lvl 1
Message 2 of 2

Re: I can't break out of the while loop!

I figured it out now. I added a destroy self to the Friend class, and so when the player collides with the Friend, they get the message and removes the friend.