FG Spreadshirt Swag
  1. #1

    Creating a wrapper around Token.onClickRelease...

    Hey all!

    I'm trying to create an extension for 5E that needs to "intercept" when a user clicks on a token. I've got it working with the following snippet in my onInit() function...

    Code:
    onClickRelease = Token.onClickRelease;
    Token.onClickRelease = onClickReleaseWrapper;
    ... but I'd like to "call" the original when I'm done in case some other extension overloads it too.

    Basically, I want this:

    user clicks token on map -> execute my "wrapper" extension -> "wrapper" extension calls original handler -> original returns -> "wrapper" returns

    This outline has worked well for other extensions (I use it extensively in the ImprovedCritical one...not for token clicks but for other things), but I can't find Token.onClickRelease in the 5E or CoreRPG rulesets, and when I try to add a call to "onClickRelease" I get an error because onClickRelease ends up being set to "nil" in the init function (i.e. Token.onClickRelease is "nil" as well). I must be going mad because my wrapper executes fine when the mouse button is released on a token, so it understands "Token.onClickRelease".

    Please encourage me that I'm just ignorant and not mental.

    Thanks!

  2. #2
    onClickRelease is not something that can be wrapped or replaced.

    Certain types of APIs are called handlers. For handler APIs, several scripts can register callbacks for those events, and all of them will be called.

    Regards,
    JPG

  3. #3
    Thanks Moon!

    Forgot about handlers. But the documentation isn't exactly helpful - it tells me that Token.onClickRelease is a handler, but not how to register a callback for it. I see callbacks registered for other things like "ActionManager.registerTargetingHandler" (I've used ones like ActionsManager.registerPostRollHandler before), but I don't see how the onClickRelease one works or why my code snippet above even calls my function at all.

    Any advice?

    Thanks again!

  4. #4
    Handlers are a specific type of registration in the API; and you always assign as Token.onClickRelease = <function>.

    The register handler functions that are part of the global scripts in the rulesets are completely different.

    Regards,
    JPG

  5. #5
    Gotcha...thanks!

    The thing that was throwing me was that I don't want my extension to do anything if I am holding the CTRL, ALT, or SHIFT keys while I click on the token because I didn't want to step on other extensions that might do that, which is why I wanted to "call" the default handler when I was done with my extension.

    In lieu of that, I added something like this:

    Code:
    if Input.isControlPressed() then 
        return;
    end
    ... which did prevent my extension from doing anything when the CTRL key was pressed while clicking, but also removed the "default" CTRL-click ability to target a token.

    So, I did the opposite and put an "if" guard around the entire thing:

    Code:
    if (button == 1) and (not Input.isControlPressed()) and (not Input.isShiftPressed()) and (not Input.isAltPressed()) then
        ... all the things ...
    end
    which makes everything play nice together.
    Last edited by TheoGeek; January 28th, 2021 at 20:11.

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
  •  
DICE PACKS BUNDLE

Log in

Log in