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

[D&D5E] Small question about "@{selected}"

In attack rolls, you usually see things like {{rname=[Weapon Name](~-123456789_123456|weapon_damage_roll)}} that highlight a clickable button within the attack roll in the chat area to call for the weapons damage roll. I don't like using ID's as it's tedious, and god forbid using nested query macros with an ID that contains HTML Entity necessities. I learned that I can instead use (~my_char_name|weapon_damage_roll) instead, which helps alleviate that issue. Now, newly, I have discovered that instead of that, I can simply use (~selected|weapon_damage_roll), as well as call macros via %{selected|ability_macro} My question is, what are some of the implications and possible issues in replacing IDs/Names with "selected"? Are there any? I imagine that a pro to this is Portability among character sheets, but how does "selected" actually work here? Does it read the name of the sheet it is being ran from and append itself with said character data? Does it attempt to run the chosen macro using the data from a token that is currently selected? Are there any ways for me to mess this up by using this in place of actual char names? I am making a macro for Artificer's Artillerist subclass for Sentry Actions (Spawn, Despawn, Activate, Detonate), and am working on the Activation macros - I have made it so the Flamethrower NPC has a macro for its damage rolls, but in my Sentry Action macro (which is on my characters sheet), if I were to run "Sentry Action, Activate Sentry, Flamethrower", it would run an attack roll which would then call upon the Damage Roll Macro found within the NPC's sheet. Question there being, would using ((rname=[Flamethrower](~selected|Flamethrower_damage_roll) look for %{Flamethrower_damage_roll} on my character sheet, or the flamethrower NPC's? Is that how it works? Edit - I just realized that the whole time i was testing this, I had my characters token highlighted (probably to enter my sheet) De-selecting the token made rolls using "selected" not work, which tells me that it is indeed based on the token you select. That is pretty neat and I can see that being very good for GM's or Players using multiple characters. Are there any alternatives to this that only take the names of the character sheet they are on? Something both Portable yet not requiring token selection?
1711375264

Edited 1711396769
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Here's a quick rundown: Using 'selected' will fill in that character reference with the selected token Using 'target' will fill in that character reference with a token the system will promote you for at time of execution Using 'target|tag1... target|tag2... ' will fill in that character reference with multiple tokens the system will prompt you for at time of execution Using a character name will work fine, but will break if you change the character name Using a character ID will work even if you change the character name, but will break if you transmogrify it into a new game. If you are writing an ability that references another ability on the same sheet, in most cases you can eliminate the character reference altogether: '[button name](~abilityName)'. Each has their best usage. You can read more about the syntax of various references to Abilities and Macros in the  Macro Character Sheet  entry on the wiki. and other spots. I would strongly recommend the use of a Macro Character Sheet (also called a Macro Mule) for general macro writing.
I saw that term earlier "Macro Mule", but now understand better, I'll look more into that Can you elaborate more on Targeting? I am not sure what being promoted for the time of execution means. I'll try [button name](~ability name), but in my experience it just results in an error saying "TypeError: Vn is undefined"
I think promoted might've been an autocorrect for prompted. When you use @{target} references, Roll20 will then prompt the sender to choose a target token. It's used in macros to say who the target is or get values from the target like name or armor class, etc.
Ah, I see- very interesting
1711383891

Edited 1711384044
vÍnce
Pro
Sheet Author
Just to add; "@{selected|" and "@{character_name|" only distinguishes which character you are referencing while rowid(the exact repeating attribute regardless of it's position within that repeating section) or row index(a repeating row attribute at a given index/position within that repeating section).  rowid and row index are often used along with "@{selected|" or "@{character_name|" to access attribute data. 
.█████╗ ██╔══██╗ said: I saw that term earlier "Macro Mule", but now understand better, I'll look more into that Can you elaborate more on Targeting? I am not sure what being promoted for the time of execution means. I'll try [button name](~ability name), but in my experience it just results in an error saying "TypeError: Vn is undefined" If you want to see a fairly complex Macro Mule, you can look at the D&D 5E Statblock Macro Mule  that I created.  It's a single character that can be used in any D&D 5th Edition game using the 'D&D 5E by Roll20' character sheet.  Using just a few Collections Macros, you can select any token, run a Collection Macro, and it will generate a chat menu message with information about the character (such as a list of actions the character can perform).  Each of the actions is also a button that can be clicked to roll the action, just like opening the sheet and clicking on the action from within the sheet. It uses a lot of '@{selected|' references to pull information from the selected token's character sheet, as well as some other tricks to insert the 'character_name' in places.
1711396961
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
.█████╗ ██╔══██╗ said: I saw that term earlier "Macro Mule", but now understand better, I'll look more into that Can you elaborate more on Targeting? I am not sure what being promoted for the time of execution means. I'll try [button name](~ability name), but in my experience it just results in an error saying "TypeError: Vn is undefined" Not sure where "Vn" came from, but the [button name](~ability name) is a very specific (but very useful for Macro Character Sheets) case where the code for the button and the ability being referenced both exist on the same sheet . And Joshua is correct: "promoted" was an autocorrect for a mis-typed "prompted". The system throws up a dialog box asking you to click on the target token you want to reference.
Gotcha, but yeah I'm not really sure why I get Vn errors. Here's an image of what that looks like too when running this: &{template:default}{{name=Shinespark Charge-Check: }}{{Feet Ran: ?{ft ran}}} {{Athletics Check Req [[ceil(?{ft ran}/10)+8]]}} %{athletics} where "%{athletics} is the roll causing the error unless I do some ID'ing (ie %{char_name|athletics}) Happens allthesame when doing button macros like that
I've tried another method Thought something like @{@{character_name}|athletics} would work, and hilariously enough I found someone else did that exact same thing as well , but it did not work. I then tried making an attribute called "name" with my characters name, but that had basically equal results. I saw the prefix trick, and I had created such already for another macro (dynamic name inputs depending on resource value), but even that doesn't seem to work here's what I tried with that: @{prefix}@{character_name}|athletics}. It works for attribute values, but not so much ability (%) ones EDIT I think I discovered a way to get it to work kinda The Prefix Trick, part 2 Attribute: prefix2 Value: %{ Macro: @{prefix2}@{character_name}|athletics}
1711401653
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
We are talking about several different things here. To begin with, if this is a token action (a macro saved on the character sheet in the Attributes and Abilities tab), then this will work: &{template:default}{{name=Shinespark Charge-Check: }}{{Feet Ran: ?{ft ran}}} {{Athletics Check Req [[ceil(?{ft ran}/10)+8]]}} %{selected|athletics} If you want to decide which token/character to use when running the macro, then this will work: &{template:default}{{name=Shinespark Charge-Check: }}{{Feet Ran: ?{ft ran}}} {{Athletics Check Req [[ceil(?{ft ran}/10)+8]]}} %{target|athletics} Both of these will automatically roll the athletics check when the macro is run. Your original post was calling for a clickable button to be posted in chat. In which case, the roll template would be processed and displayed with a button which one could click to roll the athletics check. Which in this case would be something like this as an Ability: &{template:default}{{name=Shinespark Charge-Check: }}{{Feet Ran: ?{ft ran}}} {{Athletics Check Req [[ceil(?{ft ran}/10)+8]]}}{{Roll=[Atheletics](~athletics)]] Or this as a standalone macro (which would require a token to be selected or targeted, depending on the identifier of selected or target): &{template:default}{{name=Shinespark Charge-Check: }}{{Feet Ran= ?{ft ran}}} {{Athletics Check Req= [[ceil(?{ft ran}/10)+8]]}}{{Roll= [Athletics](~selected|athletics})}} or &{template:default}{{name=Shinespark Charge-Check: }}{{Feet Ran= ?{ft ran}}} {{Athletics Check Req= [[ceil(?{ft ran}/10)+8]]}}{{Roll= [Athletics](~target|athletics})}}
Yeah, my apologies for the back and forth. I think my primary hope was to find a way to keep macros portable while sticking only on the character sheet they are on when ran, and had initially thought that "selected" was the way and then kind of delved a bit back and forth with other kinds of methods. (To clarify what I just said, since I think I could've worded that better, my main goal is reducing the need to click on stuff while maximizing what I can do with them, in this case, make macros portable, while reducing the amount of clicking (tokens, queries, so forth) that I have to do in order to utilize them) Using a different example (ie the athletics one) was probably a bad idea on my part. I suppose for my sentry ones though, if I want to make the macros on my character sheet for it portable, I can just use the prefix2 thing I thought of. However, I suppose that it wouldn't be needed if I didn't get the Vn error - what can I do to mitigate such a thing? I tried the first example of clickable buttons you showed, but it is still erroring as it shows the clickable button, but when pressed gives the Vn error Does having a name with non-standard characters cause an issue?
1711429132
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
.█████╗ ██╔══██╗ said: Does having a name with non-standard characters cause an issue? It surely can, particularly if some of the characters are punctuation. Try renaming the character with basic alphanumeric characters and see if the problem occurs.
Doesn't seem that way, I changed it to "zeebe", but no change
1711434958
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Which exact macro code are you running to give that result? Please include detailed repro steps, and if you are referencing anything with the "prefix trick". Also confirm that you are using the D&D 5th Edition by Roll20 Sheet. If you are using another 5e sheet, the results we are getting might be in disagreement.
The one I tested that resulted in the above image is this code here: &{template:default}{{name=Shinespark Charge-Check: }}{{Feet Ran: ?{ft ran}}} {{Athletics Check Req [[ceil(?{ft ran}/10)+8]]}}{{Roll=[Atheletics](~athletics)]] And yes, I am using the D&D5E by Roll20 Character Sheet
1711462125
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I did correct the syntax on that macro. You had closed it with "]]" instead of "}}". Nevertheless, try as I might, I can't reproduce the error you are getting. Nor can I find any report of that error's wording on the site. I'm wondering if it is possibly due to something on that specific character. You could try it on a different character. Note that as you have written it, the athletics button will only work if the code is run from an Ability on the Attributes and Abilities tab of the character. It will not work if entered directly in chat, nor is saved as a collections macro.
I did notice the syntax error, I had accounted for it during testing, so that it didn't mess with anything. I am not certain if this would be equal, but if I run the same command on an NPC called "Force Ballista", I get the same error as well. If I try this on another proper D&D5E player sheet named "bar wad", I still get the same error as described. For clarification purposes, I will confirm that the sheets being used are D&D5E by Roll20, and the location the macros are being ran is within the "Attributes and Abilities" tab under Abilities inside of the character sheets. The exact macro I use runs as such: &{template:default}{{name=Shinespark Charge-Check: }}{{Feet Ran: ?{ft ran}}} {{Athletics Check Req [[ceil(?{ft ran}/10)+8]]}}{{Roll=[Atheletics](~athletics)}} No prefix tricks are in play during these tests. The macro runs its intended operation up until I go to click on the prompt generated by "{{Roll={Athletics](~athletics)}}", where it then displays the error itself. It is an odd bug, and one I've been having for a bit now.
1711464114

Edited 1711464125
I just tested on a few characters, including a new one I named 'Force Ballista' and they all worked correctly for me.  I'm not seeing the "TypeError: Vn is undefined" message either.  If you want to PM me a game invite (feel free to make a copy first and invite me to that) and promote me to GM I can take a look and see if I notice anything weird.
Just to confirm, are you saving the ability then running it or are you using the test button whilst still editing? Because the latter would break the ability button in chat.
RainbowEncoder said: Just to confirm, are you saving the ability then running it or are you using the test button whilst still editing? Because the latter would break the ability button in chat. Huh, well how bout that Yeah, that uh.. that was it, so it seems. For the athletics check it works, but for other macro calls, it seems to not work all the time? Testing still Thanks for noting that. Does it only work for [Button Name](~ability name), or also %{ability name}?
Abilities always require a keyword such as selected or the character name. However using attributes to make that happen can cause problems. The difference between running an ability and testing an ability is the difference between using %{keyword|ability name} and putting the ability text (almost) directly into chat. As a result of the order of operations abilities get resolved before attributes and that loops. So when running an ability the ability has to be resolved first and the content of that ability is processed with attributes being resolved before the next round of ability resolution. When testing an ability the content starts processing with ability resolution; this can break attempts to use attributes in ability references. In conclusion something like %{@{character_id}|THE_ABILITY_NAME} works when running an ability; but is broken when testing it.
I see. That is very interesting - so "%{@{character_name}" / %{@{character_id}" work when not using the test button.. that is weird, but very helpful to know. I guess I have no particular need for my prefix2 attribute then, eh? Though it did seem to allow running such macros while testing