OnMenuSelect not triggering?

Find quick help here to get you started with Hollywood
Post Reply
Arminius
Posts: 10
Joined: Tue Sep 01, 2015 7:33 am

OnMenuSelect not triggering?

Post 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?
User avatar
jPV
Posts: 600
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: OnMenuSelect not triggering?

Post 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:

Code: Select all

Repeat
    WaitEvent
Forever
...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.
Arminius
Posts: 10
Joined: Tue Sep 01, 2015 7:33 am

Re: OnMenuSelect not triggering?

Post 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?
p-OS
Posts: 167
Joined: Mon Nov 01, 2010 11:56 pm

Re: OnMenuSelect not triggering?

Post 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.
Arminius
Posts: 10
Joined: Tue Sep 01, 2015 7:33 am

Re: OnMenuSelect not triggering?

Post 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. 8-)
User avatar
jPV
Posts: 600
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: OnMenuSelect not triggering?

Post 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
Arminius
Posts: 10
Joined: Tue Sep 01, 2015 7:33 am

Re: OnMenuSelect not triggering?

Post 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 :)
Post Reply