Sure, can be done easily. 2012/6/20 René Dudfield <[email protected]>
> > > On Wed, Jun 20, 2012 at 9:01 PM, DR0ID <[email protected]> wrote: > >> On 20.06.2012 20:02, Szymon Wróblewski wrote: >> >> >> # version 1: >> while True: >> for e in pygame.event.get() >> if e.type == NETWORK and isinstance(e.packet, echo): >> user, msg = e.packet >> print '%s: %s' % (user, msg) >> host.send(echo('me', raw_input()) >> >> >> Hi >> >> if you go with this pattern then I would suggest to avoid >> 'isinstance(...)'. I would suggest to do it like the key events in pygame: >> >> if e.type == pygame.KEYDOWN: >> if e.key == pygame.K_ESCAPE: >> # react >> >> So my suggestion would be something similar for networking packets: >> >> if e.type == pygame.NETWORK: >> if e.packet_type == echo: >> # do whatever needs to be done here >> >> >> Maybe there is a better name for 'packet_type' >> >> ~DR0ID >> >> > > What about just net? > > if e.type == pygame.NETWORK and e.net == echo: > pass > > > > >
