Beginner Python Game Issue

Started by
9 comments, last by Goran Milovanovic 11 years, 4 months ago
So, I just started learning Python. I use VB regularly and thought, let's try something new.

Now the juicy stuff...

I decided to borrow a simple ball bouncing program and recreate it. Although I typed it, it is an exact replica. I keep getting syntax errors at the display.get_caption() AND if I comment that out, at the "while" command... Help.

(pygame installed as well)
[source lang="python"]# My first game!

from pygame import * #Use pygame's funcitons

ballpic = image.load('ball.png')

done = False

ballx = 0 # Ball position variables
bally = 0
ballxmove = 0
ballymove = 0

init () #start pygame
screen = display.set_mode ((640,480)
display.set_caption('Ball Game')

while done == False:
screen.fill(0) #fill screen with black
screen.blit(ballpic, (ballx, bally)) #draw ball
display.update

time.delay(1)

ballx = ballx + ballxmove #update ball position
bally = bally + ballymove

if ballx > 600:
ballxmove = -1
if ballx < 0:
ballxmove = 1
if bally > 440:
bally = -1
if bally < 0:
bally = 1

for e in event.get(): #Check for ESC pressed
if e.type == KEYUP:
if e.key == K_ESCAPE:
done = True
[/source]
Advertisement
Just from quickly glancing at it i see this...


screen = display.set_mode ((640,480)


Looks like you're missing the last ")" on that line, which would probably cause the error.

Hope that helps! smile.png
Are you serious?! Wow. Thank you. Thank you. Thank you.


Something so simple....

Side question. I'm using Notepad++ to compose code. Is there any suggestions to another program that may help with error correction?

Are you serious?! Wow. Thank you. Thank you. Thank you.

Something so simple....
Side question. I'm using Notepad++ to compose code. Is there any suggestions to another program that may help with error correction?


No problem.

As far as programs go, you could try going the IDE route. Visual Studio with python tools or eclipse with the python plugin are a couple of options. They might help you out a bit, but probably not significantly.

I tried Visual Studio and python tools before, but switched to sublime text 2 because sublime just seems so lighweight. Visual Studio really didn't seem to help me that much when looking for errors. Also, most of the time, I was looking at runtime errors from the program output.

I think you'd be fine with just a text editor like notepad++ (or Sublime Text 2, which I recommend), and you'll learn to spot these things as you go along.

Good luck. :)
While probably not best for starting off, once you have more experience under your belt and move on to bigger projects I highly recommend the PyCharm IDE found at http://www.jetbrains.com/pycharm/. You may use it free for 30 days and after that you must purchase a license. At the time of this writing a personal license may be purchased at $99 USD.
I use Komodo Edit by ActiveState on Windows for both Python & Pygame. Works quite well.
The only complaint I've got is the autocomplete does not always "see" the correct classes and functions when looking for pygame guidance.
My solution is the keep the pygame documentation open all the time and refer to that to see where things are located rather than rely on autocomplete.
[size=2]Bang Bang Attack Studios
Senior Technical Director
Professional Typographer / Letterer Comic Art Commissions Profile
Geany is a pretty decent IDE for Python imho, but to get it to execute your scripts you'll have to set the path (assuming your using Windows) and might want to set the indentation to just use spaces. But that's pretty easy to setup.
Python sux unless its used in blender. JK
Im joking I just don't like the fact that its interpreted, platform dependencies are the worst lol

Geany is a pretty decent IDE for Python imho, but to get it to execute your scripts you'll have to set the path (assuming your using Windows) and might want to set the indentation to just use spaces. But that's pretty easy to setup.


Geany is really nice for Python :)

This topic is closed to new replies.

Advertisement