WaitEvent() after PeekEvent() to get EventSource()

BlitzPlus Forums/BlitzPlus Beginners Area/WaitEvent() after PeekEvent() to get EventSource()

Mr. Write Errors Man(Posted 2005) [#1]
I call WaintEvent() after PeekEvent() gives me something, so that I can check EventSource() etc. Is there a downside doing code like this? There isn't a need for FlushEvents if I call WaitEvent() whenever PeekEvent() gives an event, right?

Event = PeekEvent()
If Event <> 0 Then
  Event = WaitEvent()
  ... do something about the events...



Kevin_(Posted 2005) [#2]
some people, honestly....

Here is one for you....

asd asg 356 eg 57u 5h3 57u 5736u 36u ?

Any ideas?


CS_TBL(Posted 2005) [#3]
uh Fox..

o_O

What's so difficult about a normal typical daily boring loop? Like this:
Repeat
  Delay 2
  Waitevent()

  If EventID()=$803 quit=true

  If EventID()=$401
    If EventSource()=button01
    EndIf
    If EventSource()=button02
    EndIf
    If EventSource()=button03
    EndIf ; etc.
  EndIf

  If EventID()=$201
    If EventSource()=MyCanvas
    EndIf
  EndIf
Until quit


Don't make things more difficult than they are..


Lattyware(Posted 2005) [#4]
By doing as fox suggests it means that it loops regardless off whether there is an event.


CS_TBL(Posted 2005) [#5]
And what if my loop is inside a timer ?


Mr. Write Errors Man(Posted 2005) [#6]
CS_TBL,

There are a good number of reasons. The main reason being that my game logic is not based on waiting for events to occur. I also prefer to have clean code, and wrapping all the event based code within a single IF is a big plus from that viewpoint.


Lattyware(Posted 2005) [#7]
Say you have 2 windows, one working on a canvas and one with a set of gadgets. You don't want to have to press a button or do somthing everytime you want somthing to happen on the canvas.


CS_TBL(Posted 2005) [#8]
Which is why I'd put that update routine inside a timer :)


Rottbott(Posted 2005) [#9]
I do it like this:

Repeat
    Select WaitEvent(0)
        Case $803
            Exit
        ; Other event handling goes here

    End Select

    ; Game logic code goes here

Forever


WaitEvent() doesn't have to wait!