[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Re: Pygame not handling keyboard tracking correctly



diliup gabadamudalige wrote:
I called event.clear() cause it says in the Pygame documentation that if you leave unused events on the buffer that eventually it may fill up and cause the program to crash.

What it says is:

    If you are only taking specific events from the queue,
    be aware that the queue could eventually fill up with
    the events you are not interested.

But event.get() without an argument takes *all* events
from the queue, so this doesn't apply in that case.

Also can you explain why if x is True: is not correct
and

if x == True
is correct?

Neither of those is correct. You should just be doing

   if x:
      ...

There might be some very rare cases where comparing
something directly with True or False is justified,
but then whether to use 'is' or '==' will depend
on why you are doing it.

--
Greg





On Mon, Jun 23, 2014 at 11:34 AM, Greg Ewing <greg.ewing@xxxxxxxxxxxxxxxx <mailto:greg.ewing@xxxxxxxxxxxxxxxx>> wrote:

    diliup gabadamudalige wrote:

        pygame.event.clear()
        before exiting the function

        somehow when I removed that line the error stopped.


    That would definitely be it! You were throwing away any
    events that came in between calling event.get() and
    reaching the end of your function. Not a good idea when
    you rely critically on seeing *all* key up events.

    I don't know why you thought you needed to call
    event.clear(), but whatever your reason was, it was
    probably wrong.


        So may be I had to keep all the unused events for the next time
        the loop was entered. Is that correct?


    Exactly correct.

-- Greg




--
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**********************************************************************************************
This e-mail is confidential. It may also be legally privileged. If you are not the intended recipient or have received it in error, please delete it and all copies from your system and notify the sender immediately by return e-mail. Any unauthorized reading, reproducing, printing or further dissemination of this e-mail or its contents is strictly prohibited and may be unlawful. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions.
**********************************************************************************************