Program Structure

Find quick help here to get you started with Hollywood
ocean77
Posts: 111
Joined: Mon Jan 28, 2019 8:34 pm

Re: Program Structure

Post by ocean77 »

Beautiful. It works. Thank you.

So, it seems that;

MakeButton(1, #SIMPLEBUTTON, 20, 250, 120, 120, {OnMouseOut = p_Stage01EventFunc, OnMouseOver = p_Stage01EventFunc, OnMouseDown = p_Stage01EventFunc})

Will make the InstallEventHandler instruction unneeded. They are essentially the same thing? Is that a correct assumption? The script seems to work without it so I guess so. Just want to make sure.
Bugala
Posts: 1168
Joined: Sun Feb 14, 2010 7:11 pm

Re: Program Structure

Post by Bugala »

Yes, the difference between using OnMouseDown at MakeButton or InstantEventHandler is that when you are using InstantEventHandler and then using OnMouseDown case, it means that it is looking whenever Mouse Button is pushed down, regardless where that mouse is, that it is just looking at if mouse button is pressed down, not its location.

When using MakeButton with OnMouseDown, it will only look if Mouse is pushed down over that button.


To perhaps illustrate this better:

If you have

Code: Select all

Makebutton(1...)
Makebutton(2...)
Then if you use InstallEventHandler to handle the mouse button down situation, then that Function has no idea which button was pressed.

However, if you use:

Code: Select all

MakeButton(1, #SIMPLEBUTTON, 20, 250, 120, 120, {OnMouseOut = p_Stage01EventFunc, OnMouseOver = p_Stage01EventFunc, OnMouseDown = MyFuncOne})
MakeButton(2, #SIMPLEBUTTON, 20, 250, 120, 120, {OnMouseOut = p_Stage01EventFunc, OnMouseOver = p_Stage01EventFunc, OnMouseDown = MyFuncTwo})
In this case if you push mousebutton on top of Button 1, then it will execute MyFuncOne, if you push mouse button on top of button 2, then it will execute MyFuncTwo.

To have two different things happening, you don't need two different functions necessarily, but you can check on p_Stage01EventFunc which button was pressed, but I used two different Functions in this example to make it easier to understand.

And actually one more thing.

You could have both MakeButton have OnMouseDown, as well as InstallEventHandler having OnMouseDown, it would just mean that when ever you press a mouse button on top of any of the buttons, it would execute both the MakeButton OnMouseDown function, as well as InstallEventHandler function.

That lets say you have a function:

Code: Select all

function MyFunc(msg)
n = n + 1
debugprint(n)
endfunction
and then you use both MakeButton and InstallEventHandler to execute that function.

Then in case you push mouse button on top of a button, you would see.
1
2

printed on debug screen.

If you then go and click mouse somewhere else than on top of a button, you would see
3

printed on debug screen

This is because when ever you push mouse on top of a button, both the buttons OnMouseDown event happens, as well as InstallEventHandlers OnMosueDown event happens, so that function is executed twice.

When pushing somewhere else than on top of a mouse button, only InstallEventHandlers OnMouseDown functions happens, so that MyFunc is only executed once then.
ocean77
Posts: 111
Joined: Mon Jan 28, 2019 8:34 pm

Re: Program Structure

Post by ocean77 »

Nice. I think I understand. Thank you again. :)
Post Reply