How do I get this thing to work?

This is the place for queries that don't fit in any of the other categories.

How do I get this thing to work?

Postby Hissing Cockroach » Mon Sep 30, 2013 4:05 pm

Alright. I don't really see anything wrong with
this code(I am new to python). What it's doing is bringing up
the command line and disappearing again. Can someone help?
Here is the code:


Code: Select all
import sys, pygame, math
from pygame.locals import *


WHITE    = (255, 255, 255)
BLACK    = (  0,   0,   0)
BROWN    = (139,  69,  19)
DARKGRAY = (128, 128, 128)

BGCOLOR = WHITE

WINDOWWIDTH = 640
WINDOWHEIGHT = 480

FPS = 30



pygame.init()
FPSCLOCK = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
pygame.display.set_caption('Trig Pointer')



while True:
   
    for event in pygame.event.get():
        if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE):
            pygame.quit()
            sys.exit()


    DISPLAYSURF.fill(BGCOLOR)




   
    pygame.draw.line(DISPLAYSURF, BLACK, (mousex - 2000, mousey), (mousex + 2000, mousey))
    pygame.draw.line(DISPLAYSURF, BLACK, (mousex, mousey - 2000), (mousex, mousey + 2000))

   
    pygame.draw.rect(DISPLAYSURF, BLACK, (0, 0, WINDOWWIDTH, WINDOWHEIGHT), 1)

    pygame.display.update()
    FPSCLOCK.tick(FPS)
User avatar
Hissing Cockroach
 
Posts: 108
Joined: Sat Sep 14, 2013 2:35 pm
Location: Earth

Re: How do I get this thing to work?

Postby dboxall123 » Mon Sep 30, 2013 4:35 pm

The problem with your code is that 'mousex' and 'mousey' have not beem defined. Inside your while loop you need to write:
Code: Select all
mousex,mousey = pygame.mouse.get_pos()
Just out of curiosity, what environment are you running this in? You should run it in IDLE, that way you can see the exeption that's raised, this will give you an idea of the problem :D
dboxall123
 
Posts: 121
Joined: Fri Jul 12, 2013 5:28 pm

Re: How do I get this thing to work?

Postby Hissing Cockroach » Mon Sep 30, 2013 4:54 pm

I can't believe I didn't notice that!
Thanks!
User avatar
Hissing Cockroach
 
Posts: 108
Joined: Sat Sep 14, 2013 2:35 pm
Location: Earth


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 5 guests

cron