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

Getting tokenmod to grab multiple (variable) attributes

I'm attempting to solve a few related problems for getting roll20 to work the way I'd like, and have some questions about API implementations, mostly tokenmod (though I'm open to hearing more). I'm trying to use tokenmod to change token tooltips to reflect several related token attributes, namely in Fate Core, to grab all attributes in the category of Aspects. This means I'd like to be able to call @{selected|Aspect-HighConcept}, @{selected|Aspect-Trouble},  @{selected|Aspect-Aspect},  @{selected|Aspect-Aspect2}... But not all tokens will have the same number or title of aspects. Is there a way to iterate over all attributes of the selected token that start with Aspect-*******? And in that case, return a list with all of the attributes such that they could be inserted into a tooltip using  !token-mod {{  --set  tooltip|"Tooltip "  --on  show_tooltip }} Is there a way to use newlines in tooltips yet? Most of the posts I've seen were circa two years ago, I have a vain hope it has been addressed. Is there a way to set this tooltip script to run every time a token is introduced, or to run it for all tokens to save to their default token so that when i bring them onto the board it's already done/done automatically?
1720114247
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hi Sean 1. Might be solved with a meta script. I'll see if I can summon the metamancer. 2. No newlines or formatting in tooltips.As far as I can tell, they are just using plain native tooltip browser functionality, which just passes basic alphahnumeric characters. Maybe this could change under Jumpgate. 3. It can be done, but not sure if it can be done off-the-shelf.
Grabbing all the attributes can almost certainly be done with some MetaScripts but timmaugh or someone more proficient than I am would probably need to help with that. It could also be done with  ScriptCards  as well. There are built-in functions to get attributes. For example: !script {{ --&AttrPrefix|Aspect- --#title|Aspects List --#sourceToken|@{selected|token_id} --~|array;attributes;AspectArray;[*S:character_id];[&AttrPrefix] --%attrid|foreach;AspectArray --+|[*O:[&attrid]:attribute:name] --%| }} That will grab all of the attributes on the selected character and output the attribute name. It's just a quick example of fetching attributes with a specific prefix and looping over them. I could not get any newline working in a tooltip. ScriptCards also has the ability to perform Triggers  on events, so there could be one for an add:graphic  trigger to run a ScriptCard when a graphic is added. There are certainly more ways to accomplish various things so it's whatever you feel comfortable with and works best for you and your game.
1720120088

Edited 1720197516
timmaugh
Pro
API Scripter
Unfortunately the Metascript Toolbox does not yet have a "get all attributes that match this pattern" function. InsertArg could do it (it would construct the TokenMod command line on the fly, then give you either a button in chat, or you could have a button pointed to the ability that IA updated; TokenMod would then set the tooltip to be the resulting string that IA constructed). Let me reacquaint myself with the syntax to make that happen... Obviously (from Joshua's example just above), ScriptCards can output the value of a series of attributes that match a pattern. InsertArg can do that, too. This would be outputting a "chat-panel" of results for the attributes that meet the guidelines you specify. If you specifically need the values to get to the tooltip, we can get there, too... just making sure what you need. A couple of points regarding tooltip formatting for line breaks... 1) While we can't put linebreaks in tooltips, I have been able to achieve some control over the breaking of lines by placing this series of characters between my lines:  =============  Since the spaces matter (and those don't exactly translate to this medium), I should point out that that is a space followed by 13-equal signs followed by a space. The equal sign is a non-breaking character, so the screen rendering engine of your browser will try to keep it together. I have found 13 to be the right length so that it doesn't get force-broken in the middle of the chain of characters. Also, a hyphen does not enjoy the same "non-breaking" status (although this could maybe be a browser setting...?) otherwise you could use that character, instead. The spaces before and after give the linebreaks a place to happen, so you end up with your information organized with some visual demarcation: 2) ZeroFrame offers line-break characters , which wouldn't help for having line breaks WITHIN your tooltip, but would help if you wanted to quickly read the tooltip to chat. For instance, the above screenshot of 4 entries in the tooltip wouldn't have the 13-equal-signs between entries, but something more like {&cr}. This would make your tooltip a little more jumbled to the eye, but would render easily to chat with line breaks: But after running this command: !&{template:default}{{name=Tooltip Report}}{{Tooltip=@(selected.tooltip)}}{&simple} ...you'd get: 3) Note from that example that you can use Fetch to read the tooltip into your command line -- either to output to chat, as I did, or to include it for another script to use. Fetch is part of the Metascript Toolbox. 4) If you want the best of both worlds (formatted tooltip and clean rendering of the resulting tooltip in chat), you can use the 13-equal-signs trick to organize the tooltip, then use Plugger's  replace()  function when you want to output them to chat (Plugger is also part of the Metascript Toolbox). Here is a way to do that replacing each equal-sign-sequence with a carriage return: !&{template:default}{{name=Tooltip Report}}{{Tooltip={&eval}replace(--source|@(selected.tooltip) --find|" ============= "|{&cr})({&/eval})}}{&simple} ...which produces an equivalent output to the above: Or here is a version that separates each into its own line of the default template: !&{template:default}{{name=Tooltip Report}}{{{&eval}replace(--source|@(selected.tooltip) --find|" ============= "|"{&/tp}{&tp}")({&/eval})}}{&simple} ...which produces: 5) Caveats to consider: If you have attributes that will resolve to the exact same value, then the last example, above, will result in lost lines since the template part will be stepped on. This is similar to having a template part that is {{1=something}} and another part that is {{1=something else}}. Whichever is last will overwrite the one that came before. If you intend to use the    replace()  function  of Plugger, you will need to be careful what sort of data is in the attributes' values. Something like a closing parentheses character might cause unexpected results (ending the text detected as part of the replacement operation). Now I'll go see if I can work up an InsertArg command line for you to use to get the various attribute values into the tooltip. Question: does it matter what the name of the attribute is from which you are drawing the value? That is, do you need to know that the value of the "Aspect-Trouble" attribute is "balloons" while the value of "Aspect-HighConcept" is "loping but noble frog"?
First of all, thank you both for your prompt reply; this kind of support is invaluable and you've both been helpful on other threads I've referenced. Hats off to you, you make a huge difference in being able to bring these experiences to our friends which are at the core of our private lives. Timmaugh that equals sign hack is brilliant. The ideal behavior would be that I would be able to run this command, for either a selected token or all character tokens with all being more convenient but unnecessary. The command would take any attribute starting with Aspect-, which could be a variable number, and set the tooltip of that token to have each of them, separated by equal sign linebreaks, in the tooltip. This is so players can mouse over the token and see them without having to clog the chat, which is there for rolls. This would hopefully be for the default token, so that I wouldn't need to update the token every time I bring that token into the game. Ultimately the label isn't the most important, if players want to see that they can open the character sheet more fully. That said, if including the label is trivial, I wouldn't complain at having it available.  Thanks again for your time in this.
1720411941
timmaugh
Pro
API Scripter
OK... I wish I could abstract this to use a forselected handle to iterate over all selected tokens, and then use a SelectManager {&select} statement to get all character-representing tokens... unfortunately, due to a quirk of the way InsertArg is built, that won't work. And if that didn't make any sense, don't worry. The metascriptical gets easier the more you work with it. For now, I can give you the InsertArg + Metascript Toolbox + TokenMod version. It's not as elegant a solution as I would like, but it gets the job done. Setup First, make sure you have TokenMod, InsertArg, and the Metascript Toolbox installed. Next, I use a library/mule character named "LibraryCharacter". You can use a differently-named character; just make sure that every player has controlling rights to the character (it doesn't need to be in their journals). On this LibraryCharacter, create an ability named "AspectsToTooltip_Source" and give it this command: !token-mod --set tooltip|"ASPECTS ============= {&eval}replace(--source|AspectHook --find|⋄⋄|` ============= `){&/eval}" --on show_tooltip That one players (or whomever needs to use this process) won't need to run directly. The next one, though, they will, so put it somewhere the people-who-need-it can find it. That could be: a Collection Tab macro that you allow players to run a local ability on every user's character sheet another ability on the LibraryCharacter (if this is a GM-only thing and the GMs can access the sheet and/or tag the ability to "Show in Macro Bar." You can call this item what you wish. For our purposes, I will call it "CreateLocalAspectsToTooltip". Wherever you create it, use this command line: !ia --button#LibraryCharacter|AspectsToTooltip_Source --store#LocalAspectsToTooltip --AspectHook#getattrs{{!!c#@{selected|character_id} !!f#^f#Aspect- !!op#lve}} Usage To populate the tooltip with the associated character's Aspects, select the token on the VTT, change your "Speaking As" box (at the bottom of the Chat pane) to be that character, and run the  CreateLocalAspectsToTooltip command. You will get a button whispered to you in Chat. Click on it, then hover over the token you had selected. You should see the Aspects in the tooltip; each one will have the name and the value separated by a diamond character, with rows separated by the 13-equal signs. Explanation The  AspectsToTooltip_Source command line is a TokenMod command. The command contains an argument to fill the tooltip with information as well as another argument to turn the Tooltip "on". This TokenMod command has, where it wants to fill the tooltip, a Plugger {&eval} block (Plugger is part of the MetascriptToolbox). The {&eval} block will only be recognized (and run) when THIS command is executed (which we aren't doing, yet). The {&eval} block, as written, is going to run a replace() function, looking within the text "AspectHook" for 2 diamond characters and replacing those characters with " ============= ". "But there is no double-diamond character series in the word "AspectHook"." You're right. However, we aren't executing this command (at least, not this *version* of this command). First we run the InsertArg command (the CreateLocalAspectsToTooltip command), which is going to get the text of the AspectsToTooltip_Source command and modify it. Specifically, it's going to look for the text "AspectHook" and replace it. What it is replacing it with is the result of a call to get all attributes whose names begin with "Aspect-" (you may need to modify this bit, depending on how you have your Aspects named). The returned list will be formatted, as I said, with the attributes separated from the values with a diamond, and with two diamonds between attributes. All of that text gets inserted into the place where "AspectHook" sat, previously... so, now, Plugger has a string to search which DOES contain double-diamonds, and those are converted to the equal-sign series. At this point, we have modified our original TokenMod command line to include the Aspects from this character, and the new/altered command is saved to the character sheet as an ability named "LocalAspectsToTooltip" (the original is unchanged). The speaker gets a button in chat, and the button will run the LocalAspectsToTooltip ability. When they click on it, the selected token has his/her tooltip updated to match the Aspects.
1720416102

Edited 1720456533
So following up on the original ScriptCards example, here is a more complete example of a ScriptCard that will do what you are asking for with of course stealing timmaugh's cool space13equal signsspace trick: !script {{ --&AttrPrefix|Aspect- --&tooltipBreak|%20=============%20 --&sep|- --#title|Aspects List --#reentrant|AspectsTooltipSetter --#whisper|gm --~|array;define;TokenArray --?"[@SC_SelectedTokens(length)]" -ne "undefined array"|SetSelectedTokens --~tcount|array;pagetokens;TokenArray;[*P:id];pc --^ProcessTokenTooltips| --:SetSelectedTokens| --%_t|foreach;SC_SelectedTokens --~|array;add;TokenArray;[&_t] --%| --:ProcessTokenTooltips| --%tid|foreach;TokenArray -->SetTooltipToAspects|[&tid] --?[&ACount] -eq 0|+;No Aspects found for [*[&tid]:t-name] --?[&ACount] -eq 0|% --+|Update Default Token for [*[&tid]:t-name]? [rbutton]Set Default::SetDefaultToken;[&tid][/rbutton] --%| --X| --:SetTooltipToAspects|TokenID --~|array;attributes;AspectArray;[*[%1%]:character_id];[&AttrPrefix] --&ACount|[@AspectArray(length)] --?[@AspectArray(length)] -eq 0|ENDTOOLTIP --&tipMsg| --%attrid|foreach;AspectArray --?"[&tipMsg]X" -ne "X"|&tipMsg;+[&tooltipBreak] --&_aspectName|[*O:[&attrid]:attribute:name] --&tipMsg|+[&_aspectName(replace,[&AttrPrefix],)][&sep][*[%1%]:[&_aspectName]] --%| --~tipMsg|string;replaceencoding;[&tipMsg] --!graphic:[*[%1%]:t-id]|show_tooltip:1|tooltip:[&tipMsg] --:ENDTOOLTIP| --<| --:SetDefaultToken|TokenID --!c:[*[&reentryval]:t-represents]|defaulttoken:[&reentryval] --+|Default token updated for [*[&reentryval]:t-name] }} So as written, if you select a token or group of tokens, it will iterate over the selected list. If you do not select any tokens, it will grab all the PC tokens on the page that currently has the active player ribbon. PC tokens are defined as tokens that represent a character and have a player or players set in the controlledby list. --~tcount|array;pagetokens;TokenArray;[*P:id];pc The player ribbon page is the [*P:id] in the above and the pc is the filter for the PC tokens. These can be changed if you have a different setup. The ScriptCard will run and set the tooltip to the Aspects like so: It will also whisper to the GM to update the default token as well. It will also whisper to the GM if there are no attributes with the prefix found: Just wanted to supply that as a follow-up to the original ScriptCard I sent. This card does assume the ScriptCards Mod is installed, the 1-Click version should work, and that you want to act on PC tokens on the active player ribbon page if none are selected. Those assumptions can be modified if you want a different setup than that. Let me know if you have any questions about the ScriptCard here. EDIT: Removed the extra equal sign per timmaugh's post below. I can only apologize for that. I hope to be better in the future. Alternatively, thanks for the spot there timmaugh.
1720454278
timmaugh
Pro
API Scripter
That's a slick solution, Joshua! One minor quibble... you have 14-equal signs in the ScriptCard code. That's why the horizontal series of equals extends to the right edge of the tooltip in your screenshot. I think if you reduce that to 13 you'll get a(n apparently) centered line of equals. =D
Really appreciate the help. I'm starting by trying to implement Joshua's Scriptcard version of this, and the action seems to work correctly, but will at times return several copies of the aspect list, seemingly some of them having been previous versions of the aspects. I'm not sure this is an error with the script, though. It seems like, as some of these are from prior to installing scriptcard, that the character sheet is saving previous versions of the aspects that aren't displayed on the character sheet.  If you have any idea how one might go about deleting the non-active aspects that would be great, but I'm going to be digging into this on my own a bit.  You've both provided a lot of help, and insight into these tools that I'm only just learning to use. Thanks for your insight and support.
Okay, scratch that, I've found how to access and delete aspects and other attributes. Somehow in setting these up I've duplicated the complete list of attributes several times over. Time for a lot of clicking.