Help me understand.. Waitevent, eventsource...

BlitzPlus Forums/BlitzPlus Beginners Area/Help me understand.. Waitevent, eventsource...

Apollonius(Posted 2005) [#1]
Hi everyone...
I'm having trouble understanding some commands. How to use them, how they work exactly... I've been messing around with a button:
	Select WaitEvent() ; wait for client to do something
		Case $401 ; he touched a gadget
			Select EventSource() ; what did he touch?
				Case mConn ; if its the button
					Select EventData() ; the data returned from whatever he did to the button
						Case True ; if its true like if he clicked it
							Notify "boo" ; popup boo
					End Select
			End Select	
	End Select

This above is in my main loop and my button is called mConn. I'm trying to understand how to use Waitevent(), Eventdata() and eventsource(). Above in the code you can see my comment... maybe it tells you my train of thought, so maybe you can tell me what I did wrong and how I should view things.

This would help me greatly. btw if anyone's really good with blitz+ could you add me to ur msn? lexdark@...


CS_TBL(Posted 2005) [#2]
You don't need EventData to check for a buttonpress, you hardly need eventdata at all for most gadgets.
Eventdata is used for $201, $202 and some other stuff like textfields..

Yet better, for a button you don't even need anything else than EventSource() .. as it doesn't matter whether it's $401 or not, the *source* is the button.. and the action you can do with it is always pressing it..

Always put the 'biggest' scope outside, and work towards smaller conditions when nesting IF's

If you have a canvas and are doing a drawing-tool orso, the way to check for leftmousebutton drawing is:

If EventSource()=canvas
  If EventID()=$201
    If EventData()=1
      ; leftmousedown on canvas
    EndIf
  EndIf
Endif


But, if you have a number of buttongadgets, then you want something like this:
If EventID()=$401
  If EventSource()=button1
  EndIf
  If EventSource()=button2
  EndIf
  If EventSource()=button3
  EndIf
  If EventSource()=button4
  EndIf
Endif


As you see, source and ID is reversed compared to the canvas example.
naturally, in the button example the $401 is handy (as opposed to what I said above about buttons and purely using EventSource()) because without $401 check you'd have to run through all gadgets. By checking on $401 you'd at least know there was some button pressed (or some other gadget) so that it's at least worth browsing through all the eventsources.
The trick is to browse through the least possible conditions, which means swapping a few conditions here and there to create handy condition-scopes.

But I think it's all clearly explained in the manual anyway..

btw, I rarely use Select constructions for my event checking, some IF's are good enough, as I put my event-checking in dedicated functions, so there's never a lot to check.
Perhaps a bit too complex, but read my gadget tutorials (2) in "Blitsplus tutorials".. it deals with events, banks, and explains how to work with private stuff, avoiding globals etc.