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

@target and @selected question

Hi, When you have a token selected and target another it de selects the first token. Is anyone aware of a macro command that will automatically re select the original token after clicking on the target token. Hope that makes sense  
1747145339
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hi FFR! This is a known quirk. The token is still considered "selected" for the purposes of the macro you are running. But there are instances like this where you need to re-select the original token afterwards. As for forcing a selection via macro or script, this can't be done. Neither the Macro System nor Mod scripts can select a token; they cannot affect the GUI. Some mod scripts can fake it, but it requires a user to re-select.
Keith, Thanks for the response. It was just a thought to help the players out a bit but we're used to working with how things are so not a major issue.
1747250556
timmaugh
Forum Champion
API Scripter
Because the *first* selected token has references that still resolve (ie, @{selected|taco} ), you can use a metascript trick to get at least 1 selected token even when you use the targeting feature. Put a reference to the selected token's id *within* a {&select} tag. Like this: {&select @{selected|token_id} } As long as your message is (or starts out as) a script command, this will re-introduce the selected token AS a selected token even while all of the @{target} references resolve. For instance, if you have a script answering the handle "attack" that expects the attacking token to be selected, but then wants a target token ID in the command line, too... you can use the above trick right in the command line, like this: !attack --target|@{target|token_id} {&select @{selected|token_id} } But you don't need a script (outside of the Metascript Toolbox) to see it in action. Just select a token, enter this command, then target a *different* token... !I can get the name of the selected token like this: @(selected|token_name) even though I target a token to learn it's ID is @{target|token_id} {&simple} {&select @{selected|token_id} } And the result: REQUIRED SCRIPTS MetascriptToolbox
Timmaugh, What self respecting user of mods doesn't have the meta scrip installed !! As part of a macro I have "/fx nova-holy @[target|token_id]". How would I adapt that to work
1747275215

Edited 1747275535
timmaugh
Forum Champion
API Scripter
Ooh... the /fx command is one of those that gets eaten by Roll20 *before* the metascripts can get their hands on the message, unfortunately. The message tries to go before SelectManager can give the message a selected token, and before it can restore the "who" property. If you run an /fx command from a script, you get a non-sandbox-breaking error alerting you it couldn't find the "who"... because the "who" is the Script Moderator. I haven't worried a way around this particular corner of Roll20, but if I figure one out, I'll share it! However, if you use a script to spawn the FX, I think Nick O. has one, then you could use the metascripts to augment what the script required. Let me see if I can summon Nick or dig up the script I'm remembering...
Timmaugh, How about this one which I have as a character ability macro. !showbutton --silent  --show 'Magnus'|Saves. How would I amend this based on your meta script solution above ?
1747410317
timmaugh
Forum Champion
API Scripter
The basic way to use the {&select} tag is just to add it somewhere in your command line. ShowButtons doesn't really worry about the selected token so much as the player sending the message (to make sure that you have the rights to do the action you're trying to take -- although I found a problem with this logic in my upgrade to include the 'all' keyword; I have fixed it and the script is ready to push to the repo; you'll hopefully see it next week), so there really isn't much that the formation would do in THIS specific command line. So, just as an exercise in what it would look like, that would be: !showbutton --silent  --show 'Magnus'|Saves {&select @{selected|token_id} } Here's another example that would use the @target command, as well. imagine a script (I may write one, if I can't find one) that would spawn FX at a selected token, going in an optional direction/ending point denoted by a --target|... argument. Spawn a "nova-holy" FX wouldn't require the --target argument, since it only occurs around the source token: !fx --type|nova-holy However, if you wanted a beam between two tokens, you'd want the --target, as well: !fx --type|beam-holy --target|@{target|token_id} Now we won't have a selected token anymore, because we've used the @target syntax. In this case, we need to restore the selected token, so we'd need to use the {&select} tag: !fx --type|beam-holy --target|@{target|token_id} {&select @{selected|token_id} Make sense?
Timmaugh, Didn't realise it was as simple as tagging  {&select @{selected|token_id} on the end of a script command. so does make sense and thanks for your help.