Skip to main content
GameDev.net gamedev.net
🔒 Locked

Beginner Python Game Issue

Started by alexwasik Dec 13, 2012 at 12:38 AM 9 replies 4.3k views
Original Post
alexwasik
alexwasik
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]
CraftySharpV1
CraftySharpV1
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
alexwasik
alexwasik
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?
CraftySharpV1
CraftySharpV1

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.
dmreichard
dmreichard
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.
Developer_X
Developer_X
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.
BMO
BMO
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.
spiralseven
spiralseven
Python sux unless its used in blender. JK
spiralseven
spiralseven
Im joking I just don't like the fact that its interpreted, platform dependencies are the worst lol
miicchhii
miicchhii

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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.