Re: [pygame] Name self not defined

2009-01-28 Thread Jake b
On Tue, Jan 27, 2009 at 9:18 PM, Yanom Mobis  wrote:

> this is the code in question:
>
> class Car(Basicsprite): #car class
>def __init__(self, speedarg=(0,0)):
>self.speed = speedarg
>Basicsprite.__init__(self)
>

Is this valid to call parent constructor after other statements? ( Think
this is invalid in other languages  -- just not sure about python )
-- 
Jake


Re: [pygame] Name self not defined

2009-01-28 Thread Bill Coderre

On Jan 28, 2009, at 4:06 PM, James Paige wrote:

The "or" operator is what they call a "short circuiting" operator. If
the first part is True then the second part is never evaluated. If the
first part is False, then the second part is returned.



Ah, the "or" idiom. Read it as "or else." I learned of this as a perl- 
ism of particular delight:

open(FILE) or die "Can't open the file!";



perl also has inverted tests:

die "The file is not there!" unless open(FILE);



Not trying to start LANGUAGE WARS here, just pointing out that when  
the idioms line up with common natural-language idioms, it's  
peculiarly satisfying.


Interestingly, one rarely sees people use "and" as an idiom. It will  
execute starting with the left-most statement, and keep going until  
one of them fails, then stop, executing nothing further. So you could  
read it as "and then"




Re: [pygame] Name self not defined

2009-01-28 Thread Yanom Mobis
oh, thanks.

--- On Tue, 1/27/09, James Paige  wrote:

From: James Paige 
Subject: Re: [pygame] Name self not defined
To: pygame-users@seul.org
Date: Tuesday, January 27, 2009, 9:24 PM


-Inline Attachment Follows-

On Tue, Jan 27, 2009 at 07:18:20PM -0800, Yanom Mobis wrote:
> this is the code in question:
> 
> class Car(Basicsprite): #car class
>     def __init__(self, speedarg=(0,0)):
>         self.speed = speedarg
>         Basicsprite.__init__(self)
>     def move(self, speedv=self.speed):
>         self.rect = self.rect.move(speedv)
> 
> 
> however, when I try to import that class from python:
> 
> 
> 
> >>> from basicsprite import Car
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "basicsprite.py", line 14, in 
>     class Car(Basicsprite): #car class    
>   File "basicsprite.py", line 18, in Car
>     def move(self, speedv=self.speed):
> NameError: name 'self' is not defined
> 
> 
> 
> how can self not be defined??

You can't use "self" in the "def" line. Here is how I usually accomplish 
what you are trying to do:

class Car(Basicsprite): #car class
    def __init__(self, speedarg=(0,0)):
        self.speed = speedarg
        Basicsprite.__init__(self)
    def move(self, speedv=None):
        if speedv==None: speedv = self.speedv
        self.rect = self.rect.move(speedv)


But maybe somebody else can suggest a nicer way to do that.

---
James Paige



  

Re: [pygame] Pathfinding

2009-01-28 Thread Yanom Mobis

I'm just going to make my game tile-based, I guess.


--- On Wed, 1/28/09, Michael George  wrote:

From: Michael George 
Subject: Re: [pygame] Pathfinding
To: pygame-users@seul.org
Date: Wednesday, January 28, 2009, 8:41 AM

Yanom Mobis wrote:
> ok, i didn't get any of that
> 
There's a mask module in pygame with a Mask class that contains one bit per 
pixel.  It's not in the online docs yet, but in svn head there's a method 
called convolve that takes in another Mask.  If you start with a Mask (lets 
call it map) which has the corresponding bit set if there's an obstacle there, 
and another Mask (call it player) which has the shape of your player, then 
map.convolve(player) will have the (x,y) bit set if the player can be moved to 
(x,y).  Then you can do your pathfinding in that mask with A* or whatever, and 
the resulting path will be one where the player never touches an obstacle.

If your map is small, this will be feasible, but if it's large then building 
and searching a pixel-based map of the whole area will possibly take too long 
and you'd need to do something smarter.

--Mike



  

Re: [pygame] Name self not defined

2009-01-28 Thread James Paige
The "or" operator is what they call a "short circuiting" operator. If 
the first part is True then the second part is never evaluated. If the 
first part is False, then the second part is returned.

---
James

On Wed, Jan 28, 2009 at 04:03:27PM -0800, Yanom Mobis wrote:
>how do you use the or statement in arguments?  
>i have never seen it done. 
>   
>--- On Wed, 1/28/09, Ian Mallett  wrote: 
>   
>  From: Ian Mallett  
>  Subject: Re: [pygame] Name self not defined  
>  To: pygame-users@seul.org
>  Date: Wednesday, January 28, 2009, 4:25 PM   
>   
>  Frankly, I like this solution:   
>  self.rect = self.rect.move(speedv or (0,0))  
>  Looks Pythonic to me.


Re: [pygame] Name self not defined

2009-01-28 Thread Yanom Mobis
how do you use the or statement in arguments?
i have never seen it done.

--- On Wed, 1/28/09, Ian Mallett  wrote:

From: Ian Mallett 
Subject: Re: [pygame] Name self not defined
To: pygame-users@seul.org
Date: Wednesday, January 28, 2009, 4:25 PM

Frankly, I like this solution:
self.rect = self.rect.move(speedv or (0,0))
Looks Pythonic to me.



  

Re: [pygame] Name self not defined

2009-01-28 Thread Ian Mallett
Frankly, I like this solution:
self.rect = self.rect.move(speedv or (0,0))
Looks Pythonic to me.


Re: [pygame] Name self not defined

2009-01-28 Thread Nicholas Dudfield

Damn, still haven't learned to format after all these years:

class Car(Basicsprite): #car class   
   def move(self, speedv=None):

   self.rect = self.rect.move(speedv or (0,0))


Re: [pygame] Name self not defined

2009-01-28 Thread Nicholas Dudfield

Marius Gedminas wrote:

On Tue, Jan 27, 2009 at 07:24:13PM -0800, James Paige wrote:
  
You can't use "self" in the "def" line. Here is how I usually accomplish 
what you are trying to do:


class Car(Basicsprite): #car class
def __init__(self, speedarg=(0,0)):
self.speed = speedarg
Basicsprite.__init__(self)
def move(self, speedv=None):
if speedv==None: speedv = self.speedv
self.rect = self.rect.move(speedv)


But maybe somebody else can suggest a nicer way to do that.



The idiomatic way to express that is 'if speedv is None:'.
See http://www.python.org/dev/peps/pep-0008/

Marius Gedminas

Don't know how `idiomatic` or `pythonic` it is but I see a lot of people use 
`or` expressions:

class Car(Basicsprite): #car class
   def move(self, speedv=None):
   self.rect = self.rect.move(speedv or (0,0))


no `speedv`, in (x,y) tuple format, is ever going to bool as False
so if it `is None` it will use `self.speedv` of (0,0)







Re: [pygame] Alternatives to portmidi

2009-01-28 Thread Lenard Lindstrom

Hi Marcus,

Marcus von Appen wrote:

On, Tue Jan 27, 2009, Rene Dudfield wrote:

  

hi,

This is the most portable midi library.  It's also pretty small, and
still has active people working on it.



I thought so.
 
  

Also, it's supposed to be optional for pygame.



I know.
 
  

Platforms like freebsd don't support midi very well at all as far as I
could see.  So it's a case of supporting it on platforms that support
midi, and other platforms can come later -- if they support midi at
all.



That's right - and thus I'm wondering, whether the are alternatives to
portmidi that support other platforms as well. Though my search was
pretty unsuccessful so far.

Regards
Marcus
  
RtMidi has Irix support as well. It has a callback mechanism for input, 
useful for mapping midi messages into Pygame events. Unfortunately 
RtMidi is written in full blown C++, including exceptions. So there is 
no way to provide it as a dependency in Windows. It would have to be 
included as source in Pygame/pgreloaded.


http://www.music.mcgill.ca/~gary/rtmidi/

--
Lenard Lindstrom




Re: [pygame] Alternatives to portmidi

2009-01-28 Thread Marcus von Appen
On, Tue Jan 27, 2009, Rene Dudfield wrote:

> hi,
> 
> This is the most portable midi library.  It's also pretty small, and
> still has active people working on it.

I thought so.
 
> Also, it's supposed to be optional for pygame.

I know.
 
> Platforms like freebsd don't support midi very well at all as far as I
> could see.  So it's a case of supporting it on platforms that support
> midi, and other platforms can come later -- if they support midi at
> all.

That's right - and thus I'm wondering, whether the are alternatives to
portmidi that support other platforms as well. Though my search was
pretty unsuccessful so far.

Regards
Marcus


pgp77826kwUSY.pgp
Description: PGP signature


Re: [pygame] Name self not defined

2009-01-28 Thread Sean Berry
Hey thanks for that link Marius :)

For anyone who's interested, here's the suggestion he was referencing:

"- Comparisons to singletons like None should always be done with 'is' or
'is not', never the equality operators."

On Wed, Jan 28, 2009 at 6:15 AM, Marius Gedminas  wrote:

> On Tue, Jan 27, 2009 at 07:24:13PM -0800, James Paige wrote:
> > You can't use "self" in the "def" line. Here is how I usually accomplish
> > what you are trying to do:
> >
> > class Car(Basicsprite): #car class
> > def __init__(self, speedarg=(0,0)):
> > self.speed = speedarg
> > Basicsprite.__init__(self)
> > def move(self, speedv=None):
> > if speedv==None: speedv = self.speedv
> > self.rect = self.rect.move(speedv)
> >
> >
> > But maybe somebody else can suggest a nicer way to do that.
>
> The idiomatic way to express that is 'if speedv is None:'.
> See http://www.python.org/dev/peps/pep-0008/
>
> Marius Gedminas
> --
> lg_PC.gigacharset (lg = little green men language, PC = proxima centauri)
>-- Markus Kuhn provides an example of a locale
>
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iD8DBQFJgGidkVdEXeem148RAkO0AJ9HCXWcvCbJeJxctMEoqVlTLXNRvQCgk1Oo
> vW/kT4jEnhftgSWgEDPo5o0=
> =Ijvy
> -END PGP SIGNATURE-
>
>


Re: [pygame] Pathfinding

2009-01-28 Thread Michael George

Yanom Mobis wrote:

ok, i didn't get any of that

There's a mask module in pygame with a Mask class that contains one bit 
per pixel.  It's not in the online docs yet, but in svn head there's a 
method called convolve that takes in another Mask.  If you start with a 
Mask (lets call it map) which has the corresponding bit set if there's 
an obstacle there, and another Mask (call it player) which has the shape 
of your player, then map.convolve(player) will have the (x,y) bit set if 
the player can be moved to (x,y).  Then you can do your pathfinding in 
that mask with A* or whatever, and the resulting path will be one where 
the player never touches an obstacle.


If your map is small, this will be feasible, but if it's large then 
building and searching a pixel-based map of the whole area will possibly 
take too long and you'd need to do something smarter.


--Mike


Re: [pygame] Name self not defined

2009-01-28 Thread Marius Gedminas
On Tue, Jan 27, 2009 at 07:24:13PM -0800, James Paige wrote:
> You can't use "self" in the "def" line. Here is how I usually accomplish 
> what you are trying to do:
> 
> class Car(Basicsprite): #car class
> def __init__(self, speedarg=(0,0)):
> self.speed = speedarg
> Basicsprite.__init__(self)
> def move(self, speedv=None):
> if speedv==None: speedv = self.speedv
> self.rect = self.rect.move(speedv)
> 
> 
> But maybe somebody else can suggest a nicer way to do that.

The idiomatic way to express that is 'if speedv is None:'.
See http://www.python.org/dev/peps/pep-0008/

Marius Gedminas
-- 
lg_PC.gigacharset (lg = little green men language, PC = proxima centauri)
-- Markus Kuhn provides an example of a locale


signature.asc
Description: Digital signature