Re: [pygame] Never seen this before
On Sat, Apr 25, 2009 at 08:17:11AM -0700, Tyler Laing wrote: > Happens to everyone. It takes time(10 years or 10,000 hours) to get > good at something. I'm at about year 6-7 and I find while I still make > silly mistakes, I've become much better at catching them before or > during testing. :) Silly mistakes never go away. With experience you begin to expect them and check your assumptions more often. There have been countless times I've written unit tests for tiny functions that I couldn't possibly have written wrong, only to discover that I have in fact made a silly mistake. Marius Gedminas -- I'm unaware of anyone having implemented even a fraction of H.323 in Python. Doing so would require a special kind of dedication, and quite possibly a large amount of whiskey and prescription medication. -- Anthony Baxter signature.asc Description: Digital signature
Re: [pygame] Never seen this before
On Sat, Apr 25, 2009 at 8:17 AM, Tyler Laing wrote: > Happens to everyone. It takes time(10 years or 10,000 hours) to get good at > something. I'm at about year 6-7 and I find while I still make silly > mistakes, I've become much better at catching them before or during testing. > :) I'm at year 2, but I'm ~4000 hours...I guess I'm obsessive. I still make mistakes, though, obviously.
Re: [pygame] Never seen this before
Happens to everyone. It takes time(10 years or 10,000 hours) to get good at something. I'm at about year 6-7 and I find while I still make silly mistakes, I've become much better at catching them before or during testing. :) On Sat, Apr 25, 2009 at 8:03 AM, Yanom Mobis wrote: > oops. I should add that to my list of dumb bugs i find in the code i write. > Like this one: > > if key[K_RIGHT]: > spaceship.speed = spaceship.speed+10 > if key[K_RIGHT]: > spaceship.speed = spaceship.speed-10 > > > :) > --- On *Sat, 4/25/09, Tyler Laing * wrote: > > > From: Tyler Laing > Subject: Re: [pygame] Never seen this before > To: pygame-users@seul.org > Date: Saturday, April 25, 2009, 9:12 AM > > > Okay, I had assumed you had written your own python class, subclassing one > of the Group classes, and had used .add within the overridden method. I've > made that mistake myself. > > Looking at your code, I see the issue. For one, Group.add takes in a list > of sprites. You are passing in three separate arguments, and Group.add is > thinking they are each sprites. > > You should change > enemies.add(random.choice(("enemyblue.png", "enemycyan.png", > "enemygrey.png", "enemyyellow.png")), item, enemybullets) > > to > enemies.add(Enemy(random.choice(("enemyblue.png", "enemycyan.png", > "enemygrey.png", "enemyyellow.png")), item, enemybullets)) > > > The super method can take a class and an object as parameters, and it will > call the method on the superclass of the class given. It is the same as > Basicsprite.__init__(self, img) > > For reference, here is the documentation about Group.add: > > http://www.pygame.org/docs/ref/sprite.html#Group.add > > -Tyler > > On Sat, Apr 25, 2009 at 6:34 AM, Yanom Mobis > http://mc/compose?to=ya...@rocketmail.com> > > wrote: > >> the two files for the game are attached >> >> --- On *Fri, 4/24/09, Brian Song >> http://mc/compose?to=unlucky...@gmail.com> >> >* wrote: >> >> >> From: Brian Song >> http://mc/compose?to=unlucky...@gmail.com> >> > >> Subject: Re: [pygame] Never seen this before >> To: pygame-users@seul.org <http://mc/compose?to=pygame-us...@seul.org> >> Date: Friday, April 24, 2009, 9:57 PM >> >> If the problems fixed, yay.. If not, you should put up most/all your >> source so it's easier for people to see whats happening. >> >> >> > > > -- > Visit my blog at http://oddco.ca/zeroth/zblog > > > -- Visit my blog at http://oddco.ca/zeroth/zblog
Re: [pygame] Never seen this before
oops. I should add that to my list of dumb bugs i find in the code i write. Like this one: if key[K_RIGHT]: spaceship.speed = spaceship.speed+10 if key[K_RIGHT]: spaceship.speed = spaceship.speed-10 :) --- On Sat, 4/25/09, Tyler Laing wrote: From: Tyler Laing Subject: Re: [pygame] Never seen this before To: pygame-users@seul.org Date: Saturday, April 25, 2009, 9:12 AM Okay, I had assumed you had written your own python class, subclassing one of the Group classes, and had used .add within the overridden method. I've made that mistake myself. Looking at your code, I see the issue. For one, Group.add takes in a list of sprites. You are passing in three separate arguments, and Group.add is thinking they are each sprites. You should change enemies.add(random.choice(("enemyblue.png", "enemycyan.png", "enemygrey.png", "enemyyellow.png")), item, enemybullets) to enemies.add(Enemy(random.choice(("enemyblue.png", "enemycyan.png", "enemygrey.png", "enemyyellow.png")), item, enemybullets)) The super method can take a class and an object as parameters, and it will call the method on the superclass of the class given. It is the same as Basicsprite.__init__(self, img) For reference, here is the documentation about Group.add: http://www.pygame.org/docs/ref/sprite.html#Group.add -Tyler On Sat, Apr 25, 2009 at 6:34 AM, Yanom Mobis wrote: the two files for the game are attached --- On Fri, 4/24/09, Brian Song wrote: From: Brian Song Subject: Re: [pygame] Never seen this before To: pygame-users@seul.org Date: Friday, April 24, 2009, 9:57 PM If the problems fixed, yay. If not, you should put up most/all your source so it's easier for people to see whats happening. -- Visit my blog at http://oddco.ca/zeroth/zblog
Re: [pygame] Never seen this before
On Sat, Apr 25, 2009 at 06:33:00AM -0700, Yanom Mobis wrote: > what does the super() function do? It's a way to call the superclass version of the method you're overriding. (Technically, it's a built-in type, and not a function, but that's an irrelevant implementation detail). Read more about it: * http://www.python.org/download/releases/2.2/descrintro/#cooperation * http://fuhm.net/super-harmful/ Marius Gedminas -- Microsoft's entry in this cavalcade of horrors is Universal Plug and Play (UPnP). This is a protocol that allows [...] an end-user system to request a dynamic port-forwarding from the firewall to the box. Many network administrators will probably (rightly) recoil at letting applications on a Windows box dictate firewall policy. -- Anthony Baxter signature.asc Description: Digital signature
Re: [pygame] Never seen this before
Okay, I had assumed you had written your own python class, subclassing one of the Group classes, and had used .add within the overridden method. I've made that mistake myself. Looking at your code, I see the issue. For one, Group.add takes in a list of sprites. You are passing in three separate arguments, and Group.add is thinking they are each sprites. You should change enemies.add(random.choice(("enemyblue.png", "enemycyan.png", "enemygrey.png", "enemyyellow.png")), item, enemybullets) to enemies.add(Enemy(random.choice(("enemyblue.png", "enemycyan.png", "enemygrey.png", "enemyyellow.png")), item, enemybullets)) The super method can take a class and an object as parameters, and it will call the method on the superclass of the class given. It is the same as Basicsprite.__init__(self, img) For reference, here is the documentation about Group.add: http://www.pygame.org/docs/ref/sprite.html#Group.add -Tyler On Sat, Apr 25, 2009 at 6:34 AM, Yanom Mobis wrote: > the two files for the game are attached > > --- On *Fri, 4/24/09, Brian Song * wrote: > > > From: Brian Song > Subject: Re: [pygame] Never seen this before > To: pygame-users@seul.org > Date: Friday, April 24, 2009, 9:57 PM > > If the problems fixed, yay. If not, you should put up most/all your source > so it's easier for people to see whats happening. > > > -- Visit my blog at http://oddco.ca/zeroth/zblog
Re: [pygame] Never seen this before
the two files for the game are attached --- On Fri, 4/24/09, Brian Song wrote: From: Brian Song Subject: Re: [pygame] Never seen this before To: pygame-users@seul.org Date: Friday, April 24, 2009, 9:57 PM If the problems fixed, yay. If not, you should put up most/all your source so it's easier for people to see whats happening. #! /usr/bin/env python #main.py - main file for pystarfighter print("init...") #lvl level1 = [(0,0), (20, 0), (40, 0), (60, 0), (80, 0), (100,0), (120,0), (140,0), (160,0), (180,0), (200,0), (220,0), (240,0)] #positions of enemies #/lvl import pygame, spritemodule,random #import modules from pygame.locals import *# screen = pygame.display.set_mode((256,256)) pygame.display.set_caption("Loading") gameObjects = pygame.sprite.Group() #canisters bullets = pygame.sprite.Group() # enemybullets = pygame.sprite.Group()# enemies = pygame.sprite.Group() # clock=pygame.time.Clock() weaponheat = 0 spaceship = spritemodule.Player("spaceship.png") #create player object gameObjects.add(spaceship) # #colors blue = 0,0,255 red = 255, 0, 0 green = 0, 255, 0 black = 0,0,0 white = 255,255,255 #/colors spaceship.rect.left = 0 spaceship.rect.top = 236 pygame.display.set_caption("PyStarFighter") print("init complete") def setenemies_lvl1(): # put enemies on screen. pygame.display.set_caption("Loading Level") #tell player it's loading for item in level1: #loop throug coords in level file: lvl1 enemies.add(random.choice(("enemyblue.png", "enemycyan.png", "enemygrey.png", "enemyyellow.png")), item, enemybullets) pygame.display.set_caption("PyStarFighter") #tell player it's done def mainloop(): weaponheat = 0 while 1: # main game loop clock.tick(60) weaponheat = weaponheat - 1 if weaponheat < 0: weaponheat = 0 #ensure the weaponheat doesn't fall below zero spaceship.speed = (0,0) key = pygame.key.get_pressed() #create a list of keys #keys if key[K_RIGHT] and spaceship.rect.left < 240: spaceship.speed = (6,0) if key[K_LEFT] and spaceship.rect.left > 0: spaceship.speed = (-6,0) if key[K_SPACE] and weaponheat == 0: #shoot weaponheat = 60 bullets.add(spritemodule.Bullet("bullet.png", (0, -10))) #/keys spaceship.rect= spaceship.rect.move(spaceship.speed) for event in pygame.event.get(): #cycle events if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE: exit() for item in bullets: #loop through bullet canister if item.rect.left == 0 and item.rect.top == 0: item.rect.left = spaceship.rect.left #move the bullet to the spaceship item.rect.top = spaceship.rect.top# else: item.rect = item.rect.move(0,-6) #screen screen.fill(black) bullets.draw(screen) enemybullets.draw(screen) gameObjects.draw(screen) enemies.draw(screen) pygame.display.flip() setenemies_lvl1() #mainloop() import pygame class Basicsprite(pygame.sprite.Sprite): #create a sprite class def __init__(self, img): pygame.sprite.Sprite.__init__(self) self.image = pygame.image.load(img).convert_alpha() self.rect = self.image.get_rect() def resetrect(self): self.rect = self.image.get_rect() class Player(Basicsprite): #player ship def __init__(self, img): Basicsprite.__init__(self, img) def shoot(): pass class Bullet(Basicsprite): #bullet def __init__(self, img, speed): #speed is a tuple that describes the direction the bullet travels. Basicsprite.__init__(self, img) self.speed=speed class Enemy(Basicsprite): #enemy def __init__(self, img, initpos, bulletcanister): #bulletcanister- the sprite canister it puts the bullets in Basicsprite.__init__(self, img) self.rect.left = initpos[0] self.rect.top = initpos[1] def shoot(): #shoot a bullet self.bulletcanister.add(Bullet("bullet.png"))
Re: [pygame] Never seen this before
what does the super() function do? --- On Fri, 4/24/09, Tyler Laing wrote: From: Tyler Laing Subject: Re: [pygame] Never seen this before To: pygame-users@seul.org Date: Friday, April 24, 2009, 7:58 PM You get that kind of error when you use a recursive function, and it recurses down further than Python has room on the stack for. Typically, when you get this error, there's something wrong with your recursive function. What it appears to be doing is within your add function, its calling itself again. I think you might be wanting to call super(C, self).add(spr) where C is the class you created which has the add method. -Tyler On Fri, Apr 24, 2009 at 5:27 PM, Yanom Mobis wrote: this code level1 = [(0,0), (20, 0), (40, 0), (60, 0), (80, 0), (100,0), (120,0), (140,0), (160,0), (180,0), (200,0), (220,0), (240,0)] #positions of enemies #yatta yatta def setenemies_lvl1(): # put enemies on screen. pygame.display.set_caption("Loading Level") #tell player it's loading for item in level1: #loop throug coords in level file: lvl1 enemies.add(random.choice(("enemyblue.png", "enemycyan.png", "enemygrey.png", "enemyyellow.png")), item, enemybullets) pygame.display.set_caption("PyStarFighter") #tell player it's done is causing this problem: File "/usr/local/lib/python2.6/site-packages/pygame/sprite.py", line 325, in add self.add(spr) alot of the same message File "/usr/local/lib/python2.6/site-packages/pygame/sprite.py", line 316, in add if isinstance(sprite, Sprite): RuntimeError: maximum recursion depth exceeded while calling a Python object -- Visit my blog at http://oddco.ca/zeroth/zblog
Re: [pygame] Never seen this before
If the problems fixed, yay. If not, you should put up most/all your source so it's easier for people to see whats happening.
Re: [pygame] Never seen this before
You get that kind of error when you use a recursive function, and it recurses down further than Python has room on the stack for. Typically, when you get this error, there's something wrong with your recursive function. What it appears to be doing is within your add function, its calling itself again. I think you might be wanting to call super(C, self).add(spr) where C is the class you created which has the add method. -Tyler On Fri, Apr 24, 2009 at 5:27 PM, Yanom Mobis wrote: > this code > > > > level1 = [(0,0), (20, 0), (40, 0), (60, 0), (80, 0), (100,0), (120,0), > (140,0), (160,0), (180,0), (200,0), (220,0), (240,0)] #positions of enemies > #yatta yatta > def setenemies_lvl1(): # put enemies on screen. > pygame.display.set_caption("Loading Level") #tell player it's loading > for item in level1: #loop throug coords in level file: lvl1 > enemies.add(random.choice(("enemyblue.png", "enemycyan.png", > "enemygrey.png", "enemyyellow.png")), item, enemybullets) > pygame.display.set_caption("PyStarFighter") #tell player it's done > > > > > is causing this problem: > > > > > > File "/usr/local/lib/python2.6/site-packages/pygame/sprite.py", line 325, > in add > self.add(spr) > > alot of the same message > > File "/usr/local/lib/python2.6/site-packages/pygame/sprite.py", line 316, > in add > if isinstance(sprite, Sprite): > RuntimeError: maximum recursion depth exceeded while calling a Python > object > > > > > -- Visit my blog at http://oddco.ca/zeroth/zblog
[pygame] Never seen this before
this code level1 = [(0,0), (20, 0), (40, 0), (60, 0), (80, 0), (100,0), (120,0), (140,0), (160,0), (180,0), (200,0), (220,0), (240,0)] #positions of enemies #yatta yatta def setenemies_lvl1(): # put enemies on screen. pygame.display.set_caption("Loading Level") #tell player it's loading for item in level1: #loop throug coords in level file: lvl1 enemies.add(random.choice(("enemyblue.png", "enemycyan.png", "enemygrey.png", "enemyyellow.png")), item, enemybullets) pygame.display.set_caption("PyStarFighter") #tell player it's done is causing this problem: File "/usr/local/lib/python2.6/site-packages/pygame/sprite.py", line 325, in add self.add(spr) alot of the same message File "/usr/local/lib/python2.6/site-packages/pygame/sprite.py", line 316, in add if isinstance(sprite, Sprite): RuntimeError: maximum recursion depth exceeded while calling a Python object