PDA

View Full Version : Token IDs [5E, FGU]



GKEnialb
June 5th, 2021, 16:32
I override getDistanceBetween in my Token Height extension, but originally was just looking at both arguments being tokens. bmos was kind enough to extend that to handle points as well, but also found that tokenids are valid arguments as well:


function getDistanceBetween(token OR tokenid OR point, token OR tokenid OR point)

Can anyone give any tips on how to tell if the argument is a tokenid and if so, how to get an actual token from that? We currently use sourceToken.getContainerNode (with sourceToken being one the getDistanceBetween arguments) to determine if we're looking at a token or point.

Moon Wizard
June 5th, 2021, 16:35
If the value being passed into the API is:
* A "tokeninstance" data object - Use the data object
* A simple number value - Assume token ID; attempt to look up token ID on current image control; use that token object if found
* A table with two values (or x/y values) - Assume point; use in distance calculation

Regards,
JPG

GKEnialb
June 5th, 2021, 17:47
Thanks - that's nice and straightforward. I was overthinking it. Do you know off the top of your head anything that would call getDistanceBetween with tokenids so I can test it out in real life?

Moon Wizard
June 7th, 2021, 01:28
It was more of a parameter thrown in to allow information to be stored asynchronously based on token ID; since token instances would only be valid in synchronous scenarios. You can always test by using tokeninstance.getId(); if you really want to try it out.

Regards,
JPG

GKEnialb
June 7th, 2021, 02:39
It was more of a parameter thrown in to allow information to be stored asynchronously based on token ID; since token instances would only be valid in synchronous scenarios. You can always test by using tokeninstance.getId(); if you really want to try it out.

Regards,
JPG

Awesome - thanks for the thought. I was able to test all the cases.