PDA

View Full Version : Adding to a tokens radial menu (5e)



Stv
June 21st, 2022, 20:01
I may be asking something that's been asked before, but my furious googling has come up with very little in the way of answers, so....

How and where would I inject new scripting to add a new icon and function to the right click menu on a token that has been placed on a map from the combat tracker?

Cheers, Steve.

Moon Wizard
June 21st, 2022, 20:14
See this API reference wiki page:
https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644788/tokeninstance

Specifically, the registerMenuItem function and onMenuSelection handler registration. It works differently than window controls and window instances, because each token does not have it's own script space.

Regards,
JPG

Stv
June 21st, 2022, 21:21
Thanks for the reply Moon Wizard.

Although I'm having a bad day, (not my 1st :D )
Those 2 functions I have no problem with in the general scope of things.. I can add a new right click function to a combat tracker entity. I'm just struggling to see how I can do the same to a token on a map.
Any chance you have an actual code example ?
If not I'll sleep on it and have another look tomorrow :)

Cheers, Steve.

Moon Wizard
June 21st, 2022, 22:50
In order to get a copy of a token instance, you'll have to get access to the tokeninstance first. You can do that by using imagecontrol.onTokenAdded event or via a Token.onTokenAdd handler registration.

There is no code in CoreRPG that currently does this sort of behavior. In general, I've tried to move to having controls/functions more explicitly on screen when possible.

Regards,
JPG

Stv
June 22nd, 2022, 19:59
Thanks Moon Wizard, that helped loads :)

Cheers, Steve.

Stv
June 23rd, 2022, 07:14
oldonTokenAdd=ImageManager.onTokenAdd
ImageManager.onTokenAdd=newonTokenAdd


end


function newonTokenAdd(tokenMap)
Debug.chat("Token added to map",tokenMap)
oldonTokenAdd(tokenMap)
tokenMap.registerMenuItem(Interface.getString("ct_ searchtip"), "stv", 4)
end
Just realised I posted this in a different thread last night, so apologies for the thread resurrection.

The above code works for adding a new icon to a tokens radial menu but I can't figure out how to apply the corresponding handler.
I'm thinking it can't be done this way.

A yes or no will suffice here so I can stop chasing a 'will never work' solution :)

Cheers, Steve.

Moon Wizard
June 23rd, 2022, 18:33
No, anything listed as a "handler" can only be registered; they do not work like functions.

All handlers registered for a particular event will all fire. You don't get to control the ordering.

It's one of the reasons why I'm trying to move all the handler registrations into the onDesktopInit stage of initialization in the beta Test channel; so handler functions can be overriden in the onInit stage of initialization before they are registered as handlers.

Regards,
JPG

Stv
June 23rd, 2022, 19:30
Good to know, albeit a bit of a shame :)
I'll take a step back from where I was going with this one and maybe come up with a different angle of attack.

Thanks again Moon Wizard.