Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Using TokenMod to add numbers in a Tooltip

1660330998

Edited 1660331035
Current token bars are "full/used". I'm looking to use the tooltip area on the token to store a number. Then be able to modify the number using something like token-mod. So `--set tooltip|5` replaces anything in the tooltip with the number 5. And `--set tooltip|=+3` would then add 3 to the value (if a number) so that the value in the tooltip equals 8 in the example (or if the number added was =+0.5, the value would be 5.5). 1.) Does this work currently using token-mod? (ie. I might have my syntax incorrect) 2.) If not, is there anything else out there that supports this? (I suppose one work-around is to read the value using something like ScriptCards then do the math outside and use token-mod to write the final value) Not sure if this has been asked about previously. In my case, I cannot use the character sheet (attributes) as it is shared (think token-initiative type things). Thanks!
1660332206
timmaugh
Pro
API Scripter
I don't think the tooltip takes arithmetic modifiers since the help doc says that is "any text you want it to be." But. With two metascripts, Fetch and ZeroFrame , in addition to Token-Mod, you can do this: !token-mod --set tooltip|[\][\]@(selected.tooltip)+3\]\] ...or... !token-mod --set tooltip|[\][\]@(selected.tooltip)+?{Modifier?|0}\]\] ...or... !token-mod --set tooltip|[\][\]@(selected.tooltip)+[[1d20]].value \]\] ...or... !token-mod --set tooltip|[\][\]@(selected.tooltip)+@{selected|recovery}\]\]
Very helpful! Thanks much. Is there a way to detect an integer before operating on it (with one of those mods)? if complicated, don't worry about it, as my use case is likely unique and I can control what goes into tooltips in my games. Cheers
1660337525
The Aaron
Roll20 Production Team
API Scripter
It wouldn't be hard to write a one-off script to do all this. If you can spell out all your requirements, I can likely whip it up pretty fast. 
1660337675
timmaugh
Pro
API Scripter
Wellllllllll... yes. If you go as far as also installing APILogic and MathOps (also metascripts), you can use an  {&if...} check to see if something is at least a number: {&if NaN!={&math max(@(selected.tooltip))}} ...true case here... {&else} ... false case here... {&end} Note we're checking if the value of the tooltip evaluates as 'NaN' (not a number), so we are negating that to make our "true" case be that the tooltip is a number. Which you could use to hide the api handle of your token-mod command: !{&if NaN!={&math max(@(selected.tooltip))}}token-mod --set tooltip|[\][\]@(selected.tooltip)+3\]\]{&end} If the logical test fails, the token-mod command is dropped from the line and nothing happens. In this example, we don't need an {&else} case, but if you just want to get a message alerting you to the fact that the tooltip is not a number, you can put that in the  {&else}  case: !{&if NaN!={&math max(@(selected.tooltip))}}token-mod --set tooltip|[\][\]@(selected.tooltip)+3\]\]{&else}/w gm The tooltip for that character is not a number. It currently reads: @(selected.tooltip){&simple}{&end} Alternatively, you could use the logical test to select the value to use: ! token-mod --set tooltip| [\][\] {&if NaN!={&math max(@(selected.tooltip))}} @(selected.tooltip){&else}0{&end}+3\]\] That would use a default value of '0' if the tooltip was not a number. You could, of course, sub something else in there, like a check of an attribute on some character sheet. As for specifically detecting an integer (rather than just a number)... ...you can approach that with your IF block also testing whether there is a '.' in the text (change to ',' depending on your local settings): {&if NaN != @(selected.tooltip) && '@(selected.tooltip)` !~ .} That will trigger the false case for something like "3.2", but pass for something like "3". That doesn't get you all the way there, since "1.0" should evaluate as an integer, but it would be caught by that IF check. In a similar vein, though, your {&math} block can utilize the floor() function if you want to flatten a number to its integer value... and since it also returns 'NaN' if the supplied value is not a number, you could effectively replace the max() function from above. This would then bypass the need for the check for a decimal character, since you would have removed it in the conversion to an integer (or a NaN): {&math floor(@(selected.tooltip))}
1660337722
timmaugh
Pro
API Scripter
*sees Aaron posted* Of course, a built-to-suit script could be even easier. =D
Thanks guys! Let me think about it and get back tomorrow. I did use a workaround and want to make sure if I ask for something it will be worthwhile (worth your very valuable time!). Timmaugh, thanks for the example though, I can see the utility beyond this single use case.
I'm going to playtest using the workaround to see how that is in action. If I were to use a custom mod/api for this (calling upon the arcane powers of the Arch-scriptomancers), I think we'd want to avoid the tooltip field which is a workaround itself. Thanks for helping me think though this one.