Page 1 of 1
OnMenuSelect not triggering?
Posted: Sun Nov 12, 2017 6:16 pm
by Arminius
Hey everyone,
need some help with the creation of a simple menu:
Code: Select all
; Create the Menu
@MENU 1, {
{"File", {
{"About", ID = "about"},
{""},
{"Quit", ID = "quit"}}},
}
/* You're the chosen one */
@DISPLAY {Menu = 1}
/* Handle menu selections */
Function p_MenuFunc(msg)
Print("function triggered")
Switch msg.action
Case "OnMenuSelect":
Switch msg.item
Case "about":
SystemRequest("", "This is a test!", "OK", #REQICON_INFORMATION)
Case "quit":
End
EndSwitch
EndSwitch
EndFunction
; listen to "OnMenuSelect" event handler
InstallEventHandler({OnMenuSelect = p_MenuFunc})
What happens is that nothing happens upon the user selecting a menu item, e.g. quit. It seems as if p_MenuFunc does not get triggered. I have been searching the culprit for about half an hour now and even reverted to copying the code from the included MenuDemo example but still it's not working. I'm sure it must be something trivial - what am I overlooking?
Re: OnMenuSelect not triggering?
Posted: Sun Nov 12, 2017 6:49 pm
by jPV
How's your main loop? I can't see any in that example...
Anyway, I added this to the end of your code:
...and then it works just as expected. I can select both menu entries and they do work.
And I also had to remove some weird spaces from the code, but that's probably just a copy&paste error on my side, and you would have got proper error messages if those would be your problem.
Re: OnMenuSelect not triggering?
Posted: Fri Nov 17, 2017 1:54 pm
by Arminius
Thanks for the quick reply! Took me a while (2 kids, full-time job, you know it ...)
My main loop looks similiar to this:
Code: Select all
;main loop
Repeat
WaitKeyDown("ANY")
p_myfunction()
Forever
I take the WaitKeyDown() function simply listens for ANY key - which does not include the onMenuSelect event created by a mouse click?
Re: OnMenuSelect not triggering?
Posted: Fri Nov 17, 2017 3:05 pm
by p-OS
Arminius wrote:Thanks for the quick reply! Took me a while (2 kids, full-time job, you know it ...)
My main loop looks similiar to this:
I take the WaitKeyDown() function simply listens for ANY key - which does not include the onMenuSelect event created by a mouse click?
Exactly, you have to use WaitEvent to get notifications from other sources , like those from RapaGUI plugin.
Re: OnMenuSelect not triggering?
Posted: Fri Jan 05, 2018 3:54 pm
by Arminius
Thanks for taking the time to answer back! It has been some time but I didn't have the time to tinker with Hollywood since then. I'm still stuck and I can't seem to wrap my head around it. I rewrote my main loop to this:
Code: Select all
Repeat
If WaitKeyDown("ANY") = True
p_myfunction()
Else
WaitEvent()
EndIf
Forever
So basically I want the function to be executed whenever a key is pressed. However, if no key is pressed, I'd like to put the program into sleep.
The result however is that no keydown is detected and while I can now access the menu, it won't execute myfunction() anymore. Any idea as to why it doesn't get triggered?
I've been digging through the included help file that I find really great but I wish it would contain some more words / best practice on the main loop for noobs like me.
Re: OnMenuSelect not triggering?
Posted: Fri Jan 05, 2018 6:19 pm
by jPV
Don't put anything else than WaitEvent to the main loop, just install more
event handlers, for example like this:
Code: Select all
Function p_myfunction(msg)
DebugPrint(msg.key)
EndFunction
; listen to "OnMenuSelect" event handler, and OnKeyDown too :)
InstallEventHandler({OnMenuSelect = p_MenuFunc, OnKeyDown = p_myfunction})
Repeat
WaitEvent
Forever
Re: OnMenuSelect not triggering?
Posted: Fri Jan 05, 2018 6:48 pm
by Arminius
Thanks jPV, I figured that out a few minutes after my last post when going through the docs and code samples again. Anyway, thanks for helping out! Everything runs very well now