• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 62
  • Last Modified:

Why can't I use this as a function?

Here in the code I have a function name 'boundry' my problem is that when I call this function nothing happens but when i copy the code and use it without the function it works so.....WHAT IS THE PROBLEM?

def boundry(padx,padx_change):
    if padx < 0:
       padx_change = 10

while True:

 for event in pygame.event.get():
    if event.type == pygame.QUIT:
    if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                padx_change = -10
            elif event.key == pygame.K_RIGHT:
                padx_change = 10
    elif event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                 padx_change = 0
## if padx < 0:
##       padx_change = 10
 padx += padx_change

Open in new window

dayv jones
dayv jones
  • 2
1 Solution
Most likely variable scope.
Changing parameters can get tricky.
Flabio GatesCommented:
def boundry(padx,padx_change):
    if padx < 0:
       padx_change = 10

Open in new window

Because an integer (e.g., padx_change) is immutable.
See a discussion on stackoverflow here.
Flabio GatesCommented:
Question inactive
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now