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: 10
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: 109
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: 10
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: 84
Joined: Tue Nov 02, 2010 12:56 am

Re: OnMenuSelect not triggering?

Postby Arminius » Fri Jan 05, 2018 4:54 pm

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

Re: OnMenuSelect not triggering?

Postby jPV » Fri Jan 05, 2018 7:19 pm

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

Re: OnMenuSelect not triggering?

Postby Arminius » Fri Jan 05, 2018 7:48 pm

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


Return to Newbie questions

Who is online

Users browsing this forum: No registered users and 2 guests

cron