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

Using an attribute value as part of an attribute name in a macro

1628032242

Edited 1628032274
Grinning Gecko
Pro
Sheet Author
Let me explain... I have a sheet with a repeating Profiles section. The player can have a number of different profiles, which combine different gear/powers/etc. One of these profiles is the Default profile (assigned via checkbox that acts like a radio button, and the row ID gets saved to a global hidden attribute - `default_profile`). I'd like to use the value in `default_profile` as the row ID in a macro roll. Ex. If this is the raw attribute I want: @{repeating_profiles_-mgdb7qkcu9k8dsilkjg_strike} And `default_profile` contains "-mgdb7qkcu9k8dsilkjg", I want to do something like: @{repeating_profiles_@{default_profile}_strike} Is this possible?
Yes, this prefix trick will let you do that.
1628050799
GiGs
Pro
Sheet Author
API Scripter
You could also build the attribute text with sheet workers - when the profile is changed, a sheet worker could run and update all relevant attribute names (and dispense with the need to store the row id in an attribute). That is usually more complex, but also is sometimes the best approach, depending on the context.
1628132419

Edited 1628132497
Grinning Gecko
Pro
Sheet Author
Thanks both of you. The prefix trick is working great, but the macro is a little fugly and unintuitive. @{selected|prefix}selected|repeating_profiles_@{selected|default_profile}_strike} I still might take the populate-a-non-repeating-section-from-the-Default-profile-selection-via-sheet-worker route down the road, but this will do in a pinch.
1628134369
timmaugh
Pro
API Scripter
You know... if you used the default_profile field as the name of the profile, you could use Fetch fairly easily: *(selected.profiles.[profile_name=@{selected|default_profile}].strike (The above assumes that the field that names your repeating element has the suffix of "profile_name"; change accordingly). In fact, it could get the rowid, if you wanted: *(selected.profiles.[profile_name=@{selected|default_profile}].strike.rowid // OUTPUTS: -mgdb7qkcu9k8dsilkjg Or the row number (sheet relative): *(selected.profiles.[profile_name=@{selected|default_profile}].strike.row$ // OUTPUTS: $0 If, on the storing side, you wanted to store the specific name of the strike sub-attribute, you could use the name or name$ keywords, and store that: *(selected.profiles.[profile_name=@{selected|default_profile}].strike.name // OUTPUTS: repeating_profiles_-mgdb7qkcu9k8dsilkjg_strike *(selected.profiles.[profile_name=@{selected|default_profile}].strike.name$ // OUTPUTS: repeating_profiles_$0_strike Then you could reference the default profile attack a little more cleanly (though in that case, it might make sense to call it default_strike): @{selected|prefix}@{selected|default_strike}}
1628147904
Oosh
Sheet Author
API Scripter
Grinning Gecko said: I still might take the populate-a-non-repeating-section-from-the-Default-profile-selection-via-sheet-worker route down the road, but this will do in a pinch. If you're building the actual sheet, and not just making macros, there's a bunch of new tricks with the startRoll() function. You can have your "roll" button (actually an action button) grab the default profile, then grab that entire repeating entry, all before the actual roll starts. You can even grab user input, or the selected character, then start the roll - all with a single player click. For example - you could have two modes for your sheet. "Use default profile" for faster clicking, or "Query profile", where the user clicks the action button, is then prompted with a Query containing every name in their Profile repeating section, chooses one, and the roll proceeds to grab that repeating entry and submit the roll to the template.