OnMenuSelect not triggering?

Find quick help here to get you started with Hollywood

OnMenuSelect not triggering?

Postby Arminius » Sun Nov 12, 2017 7:16 pm

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

Re: OnMenuSelect not triggering?

Postby jPV » Sun Nov 12, 2017 7:49 pm

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.
User avatar
jPV
 
Posts: 87
Joined: Sat Mar 26, 2016 11:44 am
Location: RNO

Re: OnMenuSelect not triggering?

Postby Arminius » Fri Nov 17, 2017 2:54 pm

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

Re: OnMenuSelect not triggering?

Postby p-OS » Fri Nov 17, 2017 4:05 pm

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.
p-OS
 
Posts: 79
Joined: Tue Nov 02, 2010 12:56 am


Return to Newbie questions

Who is online

Users browsing this forum: No registered users and 3 guests