5E Character Create Playlist
  1. #1

    Capture global onMenuSelection().

    Hi.

    I'm trying to solve a particular lua issue for an extension I'm writing. I'm creating some global functionality that will add a radial menu item to many different windows.
    In this stripped down implementation what the code does is it overrides the standard Interface.onWindowOpened function correctly, and adds the menu item to the various windows radial menus.

    Later on I will filter what particular windows get the menu item by w.getClass().getText() filtering.

    This part is all working so far.

    However I am unable to capture the menu item selection as I've been unable to make a global override of onMenuSelection() for the windowinstance's the menu item gets added to.

    I've tried a few different override attempts such as:
    w.onMenuSelection = menuAction;
    windowinstance.onMenuSelection = menuAction;

    But none have worked so far.

    This functionality will be applied to, to many different windows, to make it feasible to copy out and modify the individual xml files for each of those, as it would make it bad to maintain with official updates and make it more likely to clash with other extensions.

    Code:
    function onInit()
        Interface.onWindowOpened = windowCheck;    
    end
    
    
    function windowCheck(w)
        if w == nil then return; end
    
        w.registerMenuItem(Interface.getString("Test"), "Test", 5);         
        onMenuSelection = menuAction;    
    end
    
    
    function menuAction(selection, subselection, subsubselection)
        if selection == 5 then
          -- do some things
        end
    end
    




    What am I doing wrong here, how do I capture or register the capture of the override of onMenuSelection for the different window the function interacts with?

    Also is there a super() function call I should make in the menuAction function to make sure the regular onMenuSelection functionality runs as well?
    Last edited by StoryWeaver; March 30th, 2019 at 14:24.
    Extension writer, FGU Backer, Ultimate License holder.

    5E Enhancer (development and support on hold for now)

    Combat Enhancer 5E Classic (no longer officially supported, community support only)

    ps. Do not send PM's for support for the extensions I write, I will not not be able to respond there. Use the relevant forum threads instead so the community can benefit from the replies, thank you.



  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,406
    onMenuSelection is an event, not a handler - so any code using this event has to be in the script extending the control. I think you'll have to modify the script attached to each <windowclass> you want to receive the event for.

    See the difference between events and handlers here: https://www.fantasygrounds.com/wiki/...g#Using_Events

    "To take advantage of events, a script block needs to be created extending the element and defining the event function"
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  3. #3
    Thanks Trenloe.

    I've decreased the scope of the extension and have it working now.
    Extension writer, FGU Backer, Ultimate License holder.

    5E Enhancer (development and support on hold for now)

    Combat Enhancer 5E Classic (no longer officially supported, community support only)

    ps. Do not send PM's for support for the extensions I write, I will not not be able to respond there. Use the relevant forum threads instead so the community can benefit from the replies, thank you.



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Starfinder Playlist

Log in

Log in