2 Replies - 3973 Views - Last Post: 26 August 2012 - 01:32 AM Rate Topic: -----

#1 tyk1337  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-August 12

Error in the code for my Pygame game

Posted 25 August 2012 - 05:42 PM

Hello devs, I just created this account because I needed help with the code in my Ludum Dare entry. If you do not know, the Ludum Dare is a game jam where one has exactly 48 hours to create a game based on a theme announced at the start of those 48 hours, and then the games are played and the best ones are voted for to win. Anyway, I've also been a lurker here at Dream In Code for a very long time now, but I have just never had the need to make an account.

Moving on, here is my code:
#-Le Boilerplate code
import pygame, sys
from pygame.locals import *

#-Loading up the images of le balls and making le background white
redBallImage = "redball.png"
blueBallImage = "blueball.png"
#lolblueballs..
greenBallImage = "greenball.png"
blackBallImage = "blackball.png"
cursorImage = "blueball.png"
pygame.init()
screen = pygame.display.set_mode((640,360),0,32)
screen.fill((255,255,255))
cursor = pygame.image.load(cursorImage).convert_alpha()
redBall = pygame.image.load(redBallImage).convert_alpha()
greenBall = pygame.image.load(greenBallImage).convert_alpha()
blueBall = pygame.image.load(blueBallImage).convert_alpha()
blackBall = pygame.image.load(blueBallImage).convert_alpha()
x,y = 0,0
moveX,moveY = 0,0

#-Just trying out some player character movement.
while True:
    screen.fill((255,255,255))
    for event in pygame.event.get():
        if event.type == QUIT:         
            pygame.quit()
            sys.exit()
        if event.type == KEYDOWN:
        
            if event.key == K_DOWN:
                moveY = moveY + 20
            elif event.key == K_UP:
                moveY = moveY - 20
            elif event.key == K_LEFT:
                moveX = moveX - 20
            elif event.key == K_RIGHT:
                moveX = moveX + 20
        if event.type == KEYUP:
        
            if event.key == K_DOWN:
                moveY = moveY + 0
            elif event.key == K_UP:
                moveY = moveY - 1
            elif event.key == K_LEFT:
                moveX = moveX - 1
            elif event.key == K_RIGHT:
                moveX = moveX + 1            
    x = moveX
    y = moveY

    screen.fill((255,255,255))
    screen.blit(cursor,(x,y))
    screen.blit(blueBall,(100,200))
    screen.blit(redBall,(400,100))
    screen.blit(greenBall,(240,20)
    pygame.display.flip()

                



-I am using Python 2.7 and it's respective stable Pygame version.
-When I try to run the script with IDLE, I get a syntax error with the "pygame" in the "pygame.display.flip()" highlighted in red. This is one of my first times using the Pygame library, and my VERY first time using IDLE (I usually just use Notepad++ and the command line for Python).

Did a google search, did not find anything of use, and can't spot anything myself. I hope that I was courteous and wrote this post correctly and to your conveniences, and that one or two of you can help me. And I wouldn't be lying if said I don't mind how long it takes, as I only have less than 24 hours to complete and submit the game. Then again, I needed a break anyway.

Is This A Good Question/Topic? 0
  • +

Replies To: Error in the code for my Pygame game

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2090
  • View blog
  • Posts: 3,185
  • Joined: 21-June 11

Re: Error in the code for my Pygame game

Posted 26 August 2012 - 12:29 AM

Look closely at line 57. Something on that line makes Python expect that the first thing on line 58 should be something other than an identifier.

If Python gave useful syntax error messages it would probably say something along the lines of "Syntax Error: Unexpected identifier on line 58 - expected ',' or ')'".

This post has been edited by sepp2k: 26 August 2012 - 12:30 AM

Was This Post Helpful? 1
  • +
  • -

#3 tyk1337  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-August 12

Re: Error in the code for my Pygame game

Posted 26 August 2012 - 01:32 AM

Oh, I see. Rookie mistake. Sorry for wasting your time on something that trivial. The thing is, I always seem to look in the farthest away lines of code when searching for ways to fix bugs, as I guess I don't expect the problem to be near the line where I got the syntax error because my subconscious expects and overestimates me to have been able to spot the error if it was near the line. I do partially have IDLE to blame, I guess, as for this error all that popped up was a window saying something along the lines of "Syntax error, can not run.." or something like that. I thought it was strange how all other syntax errors I'd gotten where outputted in the shell with "error in line... parameters.." and actual information, yet for this one error there was no text in the shell and a window popped up. Oh well. Thank you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1