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 not working with target

Hello! I'm trying to use token mod to take away from the token bars and it has been working well for me until I added a target command in which it has stopped working, everything else in the macro works as intened but not the token mod part. If someone could help me out with this that would be great!
You need to post the macro that you are using. :)
1757559372
Andrew R.
Pro
Sheet Author
You also should tell us if it’s a Jumpgate game or Classic game, and if you’re using the Default sandbox or the Experimental sandbox.  A Jumpgate game should be using the Experimental sandbox until The Aaron tells us otherwise. ;)
1757570626

Edited 1757570715
The Aaron
Roll20 Production Team
API Scripter
API scripts rely on msg.selected to know which tokens are selected, so if you run: !token-mod --set statusmarkers|+blue It knows to add the blue status marker to each selected token. However, a bug was introduced about 7 years ago where that array is not populated if the command includes @{target}.  That applies to all the commands in a macro or ability as well, so if you have something like: !token-mod --set statusmarkers|+red --ids @{target|token_id} !token-mod --set statusmarkers|+blue The second command won't have any tokens despite your having selected some. The only way around that is by manually passing @{selected|token_id} to the second command (which only works for a single token selected), or splitting the macro/ability into two. On the topic of Jumpgate and Experimental: Experimental is required to interface with Beacon character sheets, such as the DnD 2024 sheet.  It or the default API sandbox can be used with Jumpgate or Legacy games with impunity.
1757576655

Edited 1757576754
Andrew R.
Pro
Sheet Author
Thanks for the clarification! :) Is there a MetaScriptToolbox work-around?
1757599109
The Aaron
Roll20 Production Team
API Scripter
Hmm there may be. Let me summon The Tim. 
1757601606
Gold
Forum Champion
Does that bug also prevent ColorEmote from using  @{target} ?  I was recently trying to do that, and it wasn't working. Maybe a completely seperate question than the OP. I was thinking about posting a thread to ask how to do it. (How to let a Player have a Macro that lets them ColorEmote a target token that they don't Control) The Aaron said: However, a bug was introduced about 7 years ago where that array is not populated if the command includes @{target}.  
1757603591

Edited 1757603938
timmaugh
Forum Champion
API Scripter
Andrew R.  said: Is there a MetaScriptToolbox work-around? Yes. Well, yes...ish. Yes and no. For the necessity of the xBox to interface with Beacon, there is no workaround. That's just the way things have to be because of the code required for those operations. But for the loss of the tokens selected when you use a targeting statement, there is a metascript workaround... within certain limitations. SelectManager tracks the tokens that are selected when a human-generated command is run (these messages can have selected tokens) so that if it later sees a script-generated message come through (these messages cannot have selected tokens), it can assign that package of tokens to the script-generated message. As an example, this crops up when one script calls another... for instance a ScriptCard command issuing a command to TokenMod. The ScriptCard message could potentially have selected tokens, but when it dispatches the TokenMod command, that new message will NOT have selected tokens. Why that explanation on how SM does what it does? Because when someone uses a targeting statement, that initial, human-generated message comes through with NO selected tokens, as The Aaron pointed out. That means there's nothing for SelectManager to track and/or restore. So, if we're going to work around that, we have to use SelectManager's {&select} tag and somehow refer to the tokens we want to select. This will introduce a set of selected tokens to the message. ONE token of however many we might have selected on the VTT board will be available to us this way... because even though the message won't have selected tokens, Roll20 WILL resolve @{selected|...thing...} references. So, for whatever token is selected "first" (as Roll20 sees it, which might not be the order you clicked on the tokens), we can resolve an @{selected|token_id} reference in a {&select} tag, like this: {&select @{selected|token_id} } But... that will only ever be one token. Also, for TokenMod, this construction doesn't get us very far, since we could have always used the --ids command of the TokenMod command line to instruct TM to operate on those tokens: !token-mod --ids @{selected|token_id} ... The Workaround Options If we want to operate on multiple tokens as if they were selected (or just want to take advantage of the fact that a destination script like TokenMod will operate on the selected tokens), we can use: selection criteria  (as amended  here ) store token IDs in an attribute ...to get the tokens we want.  The idea would be that you can set up a "group" of tokens and select them via either criteria (in option 1) or by reference to the attribute storing the token ids (in option 2) when you use a command that also includes a targeting statement. The idea, here, would be to designate the group in an ad hoc fashion via one command, then refer to it in a target-syntax-using command via a {&select} tag. To be clear: you will need to send 2 commands.  The first one will have tokens selected and, using one of the methods just mentioned, build a group out of them (explained below). The second message will use targeting (your existing command) and therefore will NOT have selected tokens, but SelectManager will restore the tokens to the message. You cannot compress these 2 steps into a single macro, since the inclusion of the targeting syntax mean there are no selected tokens to use in the group-building. Option 1: Criteria (Requires: MetascriptToolbox + TokenMod) Let's decide on a particular marker to use as the ad hoc group designation. I'll use "red". Knowing that when you want to run the TokenMod command (that includes a targeting statement) you will have already marked the selected tokens with "red", you would prepare your TokenMod command line, altering it to include the {&select} tag: {&select *, +*red} That means that, from now on, when you run that command, SelectManager will change the message object that reaches TokenMod to include the red-marked tokens as "selected", even if you have other tokens selected on the board and/or if you use a targeting statement (and, so, there are no selected tokens in the message). Now, in your game session, if you want to use that TokenMod command (with the targeting statement), you would need to mark the tokens with red. To do that, you would physically select them on the VTT (I know: this isn't ideal; however, it's what you're doing today if you were already relying on tokens being selected on the board, but which you've now lost because of a targeting statement). After selecting them, you'd run this command: !token-mod --set statusmarkers|red That will mark the selected tokens with the "red" marker. Now you can run your TokenMod-targeting command (altered to include the {&select} tag), and the message will still have tokens for TokenMod to act upon. If it were me (and just because the Roll20 interface can be touchy about selected tokens), I would have my "grouping" command set up like this: !{{   (^)!token-mod --set statusmarkers|-red {^&select *}   /w gm [Group](!
!token-mod --set statusmarkers|red ) }} That will first clear the red marker from all tokens on this page, then prompt you with a chat button to run the second command, assigning the red marker to your selected tokens. (The button makes the second command be its own message, unaffected by the {&select} tag in the first command.) So you'd select the tokens you want to group/target... then run the above command... then click the button that appears in chat (to apply the red marker)... then click your TokenMod macro with the targeting statement. Overall, that's 2 more clicks than your current process. Option 2: Attribute (Requires: MetascriptToolbox + ChatSetAttr) Much like the previous option, this one requires you to run a command to build your group before you use that group in a {&select} tag in your existing TokenMod-targeting line. The difference for this one is that we're going to use ChatSetAttr and store that on a character sheet. I've created a character named "CampaignMule" where I can store different datapoints I might need for the game, but if you were only a player (instead of a gm) you could store the "TargetingGroup" attribute on your own sheet (simply adjust the following command to point at your character instead of CampaignMule). This time, as part of your setup,  you would modify your TokenMod-targeting line (the command where you will ultimately need to use the {&select} tag) to look for tokens that are in this TargetingGroup attribute. In other words, add this to that command line: {&select @{CampaignMule|TargetingGroup} } Then, in your game session, if you want to build an ad hoc targeting group, you would select those tokens and then run this command: !{{   !setattr --name CampaignMule --TargetingGroup| --silent   !forselected(^) setattr --name CampaignMule --TargetingGroup|{^&if "@^(CampaignMule.TargetingGroup) " != " "}@^(CampaignMule.TargetingGroup),{^&end}@^(selected.token_id) --silent {^&delay .1} }} That will first empty the contents of the attribute, then build, in the TrackingGroup attribute, a comma-delimited list of the selected tokens. That comma-delimited list, when used in the {&select} tag noted above, will produce the list of tokens you want to use as your "selected" tokens for the command where it is included.
1757603847
timmaugh
Forum Champion
API Scripter
Gold said: Does that bug also prevent ColorEmote from using  @{target} ?  If ColorEmote works on the selected token (a good indicator of that is if the script does not require a way to designate the token in the command line; if it just "works" if you have a token selected and without having to designate a token, otherwise, it's working on the selected token), then this is likely the cause of that problem. But we can do ju jitsu. You can virtually select a token using the {&select} tag, but supply an ID at runtime via a targeting statement: {&select @{target|token_id} } That will repurpose the targeted token as a selected token. But an example more specific than that would require a ColorEmote command line so I can see all the parameters at play.
1757605304

Edited 1757606992
Gold
Forum Champion
Nevermind me, and apologies for distracting from the OP's question thread. I re-read the ColorEmote documentation again and it tells me how to do what I wanted, afterall. I tested it, and the ColorEmote Mod seems to be working fine on a targeted token afterall. Resolved that longstanding question of mine today, in a roundabout way thanks to this thread.  For the record this is what I'm working in ColorEmote for my purposes, !cem[@{target|token_id}]  {{ Here comes ✨✨ @{target|token_name} }}
some extra info the dnd game in on jumpgate and this is the part of the macro that isn't working anymore  !token-mod --set bar2_value|-4 @{selected|token_name} uses Psi! **Hit roll** [[1d20+@{selected|agility}]] vs @{target|agility}
1757632113
timmaugh
Forum Champion
API Scripter
Oh, then you can absolutely take advantage of the easiest solution. It looks like you only have one token that you need to keep selected, so you can make use of the {&select} tag with the selected tokens ID (requires the MetascriptToolbox): !token-mod --set bar2_value|-4 {&select @{selected|token_id} } @{selected|token_name} uses Psi! **Hit roll** [[1d20+@{selected|agility}]] vs @{target|agility} 
1757632991
The Aaron
Roll20 Production Team
API Scripter
If you're only dealing with a single selected token, you can handle it with just TokenMod: !token-mod --set bar2_value|-4 --ids @{selected|token_id} @{selected|token_name} uses Psi! **Hit roll** [[1d20+@{selected|agility}]] vs @{target|agility}
That works perfectly thank you so much!