Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 21st, 2004, 10:36 AM
Mike234 Mike234 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 2 Mike234 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Spot the error for the Newbie

Hello!!

Ok here is a code example i copied from a guide on Pygame.
It worked when i used IDLE and typed in line by line
But it doesnt work if I try running the code from a .py file

--error--
File "bouncyball.py", line 19
ballrect = ballrect.move(speed)
^
SyntaxError: invalid syntax

--code--
import pygame ,sys

pygame.init()

size = width, height = 320, 240
speed = [2, 2]
black = 0,0,0

screen = pygame.display.set_mode(size)
ball = pygame.image.load("e:\\ball.bmp")
ballrect = ball.get_rect()


while 1:

..for event in pygame.event.get():
.....if event.type == pygame.QUIT: sys.exit()

..ballrect = ballrect.move(speed)

..if ballrect.left < 0 or ballrect.right > width:
....speed[0] = -speed[0]

..if ballrect.top < 0 or ballrect.bottom >height:
....speed[1] = -speed[1]

..screen.fill(black)
..screen.blit(ball, ballrect)
..pygame.display.flip()


pygame.QUIT()




any ideas???????

p.s. ".." means tab,

Reply With Quote
  #2  
Old July 21st, 2004, 12:29 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 3 m 4 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
I cant see anything from what the code but maybe it was lost when you posted it? Try posting the code again using Code-tags as discribed the sticky at the top of this forum .

Also, you may want to try changing...

Code:
for event in pygame.event.get():
    if event.type == pygame.QUIT: sys.exit()


to..

Code:
for event in pygame.event.get():
    if event.type == pygame.QUIT:
        sys.exit()


Just to see if that helps,

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old July 21st, 2004, 04:47 PM
Mike234 Mike234 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 2 Mike234 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Code:
import pygame ,sys

pygame.init()

size = width, height = 320, 240
speed = [2, 2]
black = 0,0,0

screen = pygame.display.set_mode(size)
ball = pygame.image.load("e:\\ball.bmp")
ballrect = ball.get_rect()


while 1:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      sys.exit()


  ballrect = ballrect.move(speed)

  if ballrect.left < 0  or ballrect.right > width:
    speed[0] = -speed[0]

  if ballrect.top < 0 or ballrect.bottom >height:
    speed[1] = -speed[1]

  screen.fill(black)
  screen.blit(ball, ballrect)
  pygame.display.flip()


pygame.QUIT()



error:
File "bouncyball.py", line 20
ballrect = ballrect.move(speed)
^
SyntaxError: invalid syntax

Reply With Quote
  #4  
Old July 21st, 2004, 06:07 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 7
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
Quote:
Originally Posted by Mike234
Code:
import pygame ,sys


Code:
import sys

import pygame

Much better.

Quote:
Code:
size = width, height = 320, 240

Don't do this.
Do:
Code:
width = 320
height = 240
size = (width, height)

if you must.

Code:
  ballrect = ballrect.move(speed)

ballrect.move() returns something? A new ballrect? Weird.
__________________
Debian - because life's too short for worrying.
Best. (Python.) IRC bot. ever.

Reply With Quote
  #5  
Old July 22nd, 2004, 04:34 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
Not sure if this is your problem, but..

I have had similar problems with "syntax errors" which were entirely due to files mixing tab characters and spaces or just because one line has 3 spaces for indentation when 4 spaces are used in other places..

This often happens when pasting code from other sources (e.g. off a web-page). You can also cause problems if you switch editors and the editors are not configured the same way. (the use of tabs character/ number of spaces for tab).

Try loading the file into Idle then select the whole text (CTRL-A) the use the Format-"Untabify Region" menu option. Then save the file and try again. If you still get errors then search for odd indentation depths around the line reported.

I have also had indentation errors like this that only show up when a module has been included by another module.

Try to be consistent with other modules which typically use 4 spaces for each tab. You will save yourself problems in the future.

grim
__________________
*** Experimental Python Markup CGI V2 ***

Last edited by Grim Archon : July 22nd, 2004 at 04:38 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Spot the error for the Newbie


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT