-
January 27th, 2021, 22:57 #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;
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!
-
January 27th, 2021, 23:13 #2
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,541
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
-
January 28th, 2021, 03:40 #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!
-
January 28th, 2021, 05:34 #4
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,541
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
-
January 28th, 2021, 20:09 #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
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
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