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

Token-Mod to add string to multiple selected token name plates

Hi!   I'm looking to see if its possible to add a specific string multiple tokens name plates (and removing it later) but keeping the original toke name plate name.  For example.  I have selected 2 goblins and 1 wolf.  Their name plates say "Goblin" and "Wolf".   I'd like to have a macro toggle that adds some letters to their name plates such as " NR" so they become "Goblin NR" and "Wolf NR".   Then later, I can select some or all of those tokens and click the macro again (or use 2 macros if I have to) that will search the name plate for the " NR" and remove it, preserving the original name.  So back to "Goblin" and "Wolf". Is this something token-mod can do or do I need some combination of API's to do this? Much appreciated!
1728372741
Andrew R.
Pro
Sheet Author
I’d start with the MetaScriptToolbox. 
1728394437
timmaugh
Pro
API Scripter
Hi, Val... Like Andrew said, this is right up the alley of metascripts. While it sounds like you're adding the same text to every token's name, you will need differentiated results since starting with "Goblin" would be different than starting with "Wolf". That means in addition to TokenMod you'll want the Metascript Toolbox so you can use SelectManager's forselected handle to iterate over the tokens, and Fetch to pull the information at the correct time: !forselected(^) token-mod --set name|"@^(selected.token_name) NR" Removing the " NR" from the name would require another script from the Toolbox (don't worry, they all get installed if you install the Toolbox). Plugger lets you do a replace function, like this: !forselected(^) token-mod --set name|"{^&eval}replace(--source|"@^(selected.token_name)" --find|" NR"|""){^&/eval}" That would iterate over the tokens, looking for " NR" and replacing it with nothing. Note: I found a bug while verifying this syntax, and release a new version of Plugger. The update is in the pipeline for the 1-click, but I think I missed the deadline for this week's merge, so it won't happen until next week. If you install the Metascript Toolbox, you'll get the member scripts from the 1-click, and you'll get the fix automatically next week. BTW, if you want to quickly reference the tokens on the current page who have the " NR" text in their name, you can virtually select them without having to click on each one (or remember which ones are named that way). You would do that by adding this bit of syntax to your command line: {&select * NR} So, let's say you wanted to remove the " NR" from all tokens on the current page. You can use the previous example and add the {&select} syntax to arrive at: !forselected(^) token-mod --set name|"{^&eval}replace(--source|"@^(selected.token_name)" --find|" NR"|""){^&/eval}"  {&select * NR}
I installed this today and it's exactly what I'm looking for.  Works perfectly.  The removal part wasn't working so well but as you said, probably due to the bug you found.  I'll wait till it gets merged and try that part more later.  I'm just super happy this actually solves my problem! Thanks and cheers! V
1728425800
timmaugh
Pro
API Scripter
Excellent! BTW, if you need it before the merge, the new version of Plugger is up on my repository. You can get it from that link. You'd have to uninstall the existing Plugger, then add this code manually (in the "New Script" tab of your script deck). If you do that, I'd still suggest converting back to the 1-click version after the merge, just to make sure you get the future updates. (If you remove the manually-installed version of Plugger, you can install Plugger via the one-click without worry that you'll mess up the Metascript Toolbox -- that just checks to make sure the scripts are there, giving you a message if they aren't; it doesn't care whether they're installed manually or via the one-click) Give a shout if you need anymore help!
Thank you!  When does the next merge happen?  My next session where I would want to use this is next Wednesday, 16th.  If it's before then, I can wait. Thanks again for all the help and the awesome toolkit!
1728495090
timmaugh
Pro
API Scripter
I believe that (these days) the merge is supposed to happen in the early hours of Tuesday every week -- though Roll20 has been known to forget the merge periodically. If you want to know whether you have the new version, you can install the ScriptInfo script, and run: !scriptinfo Look for the entry of Plugger. If it reads 1.0.9 as the version, that's the previous version. You want to see 1.0.10:
Hi!  I decided to install the new version of plugger manually and now the removal command you posted above "sort of" works.  It works great when I select 1 token but when I select 3 or more, it seems like it only removes the "NR" on half of them.  I selected 6 tokens and 3 got the NR removed.  I tried 4 and only 2 got it removed.   Any ideas what might cause that? Thanks!
1729039498

Edited 1729039540
timmaugh
Pro
API Scripter
Hmm... I just tried in my game and everything works. I renamed a group of 8 character-representing tokens to have names that ended in " NR" and ran the test, then separately did the same for a set of 12 non-character tokens. I ran both tests a few times, and never had a dropped rename. The command I ran was this one: !forselected(^) token-mod --set name|"{^&eval}replace(--source|"@^(selected.token_name)" --find|" NR"|""){^&/eval}"  {&select * NR} I'm wondering if you're having a resource issue on your machine caused by the messages iterating too quickly...? You can try to slow them down just a tad by including a deferred DELAY tag in the line: {^& delay .1} Adding that (add it before or after the {&select} tag) will just give a little breathing room between each message. Give that a try, and if you're still having trouble, you can shoot me a PM with an invite to your game, then promote me to GM once I join. I can take a look to see if there's anything unusual going on.
1729040370

Edited 1729040399
Val
Pro
I changed my macro to yours above.  It's doing some really strange things for me.  For example, I have 3 wolves named "Wolf NR".  On the same map are a variety of other tokens including goblins and some named creatures.  Some have NR in their names, others do not.   I select the 3 wolves and click the macro.  1 wolf changes and the NR is removed, then some of the goblins (which I did not have selected) change as well.  The NR gets removed from them.  It's really odd.   I'll send a PM shortly.
1729041491
timmaugh
Pro
API Scripter
oh, sorry... my command included the SELECT tag: {&select * NR} That is going to overwrite what you actually have selected on the gameboard with ALL tokens that end in " NR". That's why the other tokens were getting renamed, too. If you remove that tag, then it will operate on *just* the tokens you have actually physically selected.