Login Register






Can Some One Help Me With My Code filter_list
Author
Message
Can Some One Help Me With My Code #1
I am using python 2.7 and i was just working with python making a pong game but i keep getting the error message "Traceback (most recent call last):
File "C:\Python27\Ping.py", line 13, in <module>
GO()
NameError: name 'GO' is not defined"

Here is my code-

---------------------------------------------------------------

Code:
import os, sys import pygame from pygame.locals import* screen=pygame.display.set_mode((640,480)) PADDLE_WIDTH=50 PADDLE_HEIGHT=10 p1Paddle=pygame.Rect(10,430,PADDLE_WIDTH,PADDLE_HEIGHT) PADDLE_COLOR = pygame.color.Color("red") SCREEN_COLOR = pygame.color.Color("black") GO puckSpeedX=1 puckSpeedY=1 PUCK_COLOR=pygame.color.Color("green") puck=pygame.Rect(320,240,10,10) GO while True: p1Paddle.left = pygame.mouse.get_pos()[0] puck.left = puck.left + puckSpeedX puck.top = puck.top + puckSpeedY screen.fill(SCREEN_COLOR) GO screen.fill(PADDLE_COLOR, p1Paddle) screen.fill(PUCK_COLOR, puck) pygame.time.delay(10) pygame.display.flip() GO if puck.colliderect(p1Paddle): puckSpeedY=puckSpeedY*-1 if puck.top < o or puck.bottom > 480: puckSpeedY=puckSpeedy*-1 if puck.left < o or puck.right > 640: puckSpeedX=puckSpeedX*-1

Reply

RE: Can Some One Help Me With My Code #2
A. Always use [ code ] tags when posting code. Please add them to this thread.

B. What the fuck is "GO" supposed to be?

Reply

RE: Can Some One Help Me With My Code #3
...GO isn't necessary, quick google shows its part of some ehow code but every other example of this code doesn't have it...just remove them.

Code:
if puck.colliderect(p1Paddle): puckSpeedY=puckSpeedY*-1 if puck.top <= o or puck.bottom >= 480: puckSpeedY=puckSpeedy*-1 if puck.left <= o or puck.right >= 640: puckSpeedX=puckSpeedX*-1

The last two cases are only checked if the first if block has passed this is not what you want. Remove one layer of indentation so that the last two cases are checked with every loop

Also change the o to 0...its a number not a letter you should be comparing against.

And puckSpeedY is not the same as puckSpeedy in the second if block, change the second occurrence to puckSpeedY

You're also going to run into hangs because you're not processing the pygame event queue. You don't need to do any handling but you do need to atleast grab the events.

Adding

Code:
for event in pygame.event.get(): pass

To the top of your while loop should do the trick.

So after all that your code should look something like

Code:
import os, sys import pygame from pygame.locals import* screen=pygame.display.set_mode((640,480)) PADDLE_WIDTH=50 PADDLE_HEIGHT=10 p1Paddle=pygame.Rect(10,430,PADDLE_WIDTH,PADDLE_HEIGHT) PADDLE_COLOR = pygame.color.Color("red") SCREEN_COLOR = pygame.color.Color("black") puckSpeedX=1 puckSpeedY=1 PUCK_COLOR=pygame.color.Color("green") puck=pygame.Rect(320,240,10,10) while True: for event in pygame.event.get(): pass p1Paddle.left = pygame.mouse.get_pos()[0] puck.left = puck.left + puckSpeedX puck.top = puck.top + puckSpeedY screen.fill(SCREEN_COLOR) screen.fill(PADDLE_COLOR, p1Paddle) screen.fill(PUCK_COLOR, puck) pygame.time.delay(10) pygame.display.flip() if puck.colliderect(p1Paddle): puckSpeedY=puckSpeedY*-1 if puck.top <= 0 or puck.bottom >= 480: puckSpeedY=puckSpeedY*-1 if puck.left <= 0 or puck.right >= 640: puckSpeedX=puckSpeedX*-1

Overall though I'd advice you take a step back and try to learn the basics of python before trying to copy and paste code to make a game. The error message you received is pretty clear.

Code:
NameError: name 'GO' is not defined

Which means exactly what it states, GO hasn't been defined but you're trying to use it to do something.
(This post was last modified: 05-13-2014, 03:25 PM by miiike980.)

Reply

RE: Can Some One Help Me With My Code #4
Ok thanks yea thats were i got the code from was ehow lol im just trying to teach my self currently so im just trying to study code that others have done in python code so thanks again

Reply

RE: Can Some One Help Me With My Code #5
(05-13-2014, 08:32 PM)PersonIAm7523 Wrote: Ok thanks yea thats were i got the code from was ehow lol im just trying to teach my self currently so im just trying to study code that others have done in python code so thanks again

Its probably a better idea to learn the language syntax before you try to 'study' code.

Reply