0

I am trying to make an easteregg for my friend in a test game for pygame I am making and sadly when I have tried to switch the main picture image it will not switch though no errors resolve! Here is the code:

carImg = pygame.image.load("ship.png")

That's the image variable

            elif event.key == pygame.K_c:
                carImg = pygame.image.load("ee.png")
                car(x,y)
                pygame.display.update()
                gameDisplay.blit(carImg,(x,y))

That's the easteregg bind,

Problem: Picture variable won't change

Tried: To switch via the 'c' key as shown above

Errors: None

HKVariant
  • 837
  • 10
  • 23

1 Answers1

0

change it to:

global carImg
carImg = pygame.image.load("ee.png")

Global variables: Using global variables in a function other than the one that created them

Community
  • 1
  • 1
lakshmen
  • 28,346
  • 66
  • 178
  • 276
  • 1
    Thank you! I can't believe I missed something so simple haha, I'll vote as top answer when the timer that stops you from voting so soon runs out. – HKVariant Oct 16 '14 at 15:52