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

Creating a Button Macro as part of a Repeating Section

1471926681

Edited 1471926737
Hi there, I'm in the middle of creating a character sheet for a game where characters can have a number of different kinds of weapons -- I've taken to the approach of using a repeating section.  Here's a snippet of code is as follows: <fieldset> <button type='roll' name='roll_useWeapon' value='&{template:weaponAttack} {{name=@{character_name}}} {{weapon=@{repeating_weapons_$X_WeaponName} - @{repeating_weapons_$X_WeaponType}}}'></button> <input type="text" name="attr_WeaponName" placeholder="Weapon Name" style="width:20%"> <select name="attr_WeaponType" placeholder="Type"> <option value="Melee">Melee</option> <option value="Ranged">Ranged</option> </select> ... However, on looking at the Macro documentation, it seems like my only two options are referring to a specific row ($0, $1...) or a specific ID -- is there a way to make a macro in a repeating section be able to reference itself, i.e. pulling in the random ID when it's first generated so that's assigned to the macro? Essentially, what I'm looking for is the ability to reference @{repeating_weapons_$X_WeaponName} where X just automatically refers to the row it's part of. Is there a better practice for doing this?
1471927729

Edited 1471927922
vÍnce
Pro
Sheet Author
Attributes within their own fieldset automatically look for attribute data within their fieldset.  Meaning, you don't have to use the longer "repating_weapons_$0_WeaponName".  You can just use an attribute's name directly eg @{WeaponName} If you are trying to access a given rows attribute or id outside a fieldset, you need to use the long name and include a row number "$X" or better yet, an ID. Someone else will need to explain how you can use sheet worker js to detect id's and insert them where needed to calculate/generate other attribute values.  Chris, Brian...?  ;-)   BTW, you need to assign a repeating class to your fieldsets to define them.  ie <fieldset class="repeating_weapons"> Cheers
Ah thanks, I'd made a few mistakes when I was cleaning up the code to use as an example on the post. Someone else will need to explain how you can use sheet worker js to detect id's and insert them where needed to calculate/generate other attribute values. Chris, Brian...? ;-) I did find an example in the Pathfinder sheet, though I was wondering if there was native support for it -- I assume that there isn't, and a sheet worker is necessary at the moment?
OK, after some testing, doing what Vince mentioned and just using the attribute reference worked: <fieldset class="repeating_weapons"> <button type='roll' name='roll_RollDamage' value='&{template:test} {{name=@{character_name}}} {{subtags=@{WeaponName} - @{WeaponType}}} {{test=@{target|token_name}}} {{result=[[1d10+@{Atk}]]}} {{opposing=vs. @{target|Def}}}'></button> <input type="text" name="attr_WeaponName" placeholder="Weapon Name" style="width:20%"> <select name="attr_WeaponType" placeholder="Type"> <option value="Melee">Melee</option> <option value="Ranged">Ranged</option> This causes each button to reference the contents of its own, which is what I was looking for.