Sign in to follow this  
alexwasik

Beginner Python Game Issue

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Just from quickly glancing at it i see this...

[CODE]
screen = display.set_mode ((640,480)[/CODE]

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

Hope that helps! [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Edited by xSharp

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
[quote name='alexwasik' timestamp='1355362691' post='5010039']
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?
[/quote]

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. :)

Share this post


Link to post
Share on other sites
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 [url="http://www.jetbrains.com/pycharm/"]http://www.jetbrains.com/pycharm/[/url]. 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote name='BMO' timestamp='1355371317' post='5010062']
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.
[/quote]

Geany is really nice for Python :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this