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

Changing attributes by toggle?

1591396601
Kraynic
Pro
Sheet Author
At first, I was thinking it would be simple (isn't this how it always goes?).  I am working on a sheet that needs to track more than one style of hand to hand training, which as the character levels has attributes that interact with a lot of buttons.  I thought about setting up toggles that would (for instance) switch what macro was being used when you hit an attack button, which would work fine if it wasn't for all the other buttons that would need a toggle.  The amount of toggles going that route really wasn't going to be much different than just creating 2 buttons for everything.  While that is certainly doable, I'm hoping that isn't really necessary. To fill in some of the details, all the attributes in the primary hand to hand section begin with "hth_", while all the ones in the secondary hand to hand section begin with "hth2_".  So there is "hth_strike", "hth_parry", "hth_dodge", "hth2_strike""hth2_parry", "hth2_dodge", as well as another 10 or 11 attributes.  Nowhere on the sheet (at the moment) are "strike", "parry", or "dodge" used as attribute names (or any of the other attributes prefixed by hth_). If I create a radio button toggle for "combatskill" that toggled back and forth between a value of 1 or 2, and then created hidden attributes named "strike", "parry", and "dodge" (and the other "bare" attributes needed), would it be possible for a sheetworker to be able to toggle the values of the bare attributes back and forth between the attributes labeled "hth_" and "hth2_"?  So if the "combatskill" toggle was on 1, "strike" would have a value of @{hth_strike}, "parry" would have a value of @{hth_parry} and so on.  If the toggle was set to 2, "strike" would have a value of @{hth2_strike}, "parry" would have a value of @{hth2_parry}, and so on. If that is possible, what would a sheetworker like that look like?  If I can get a grasp on how it works for these few attributes, I could probably add in the rest on my own.
1591398972

Edited 1591409333
GiGs
Pro
Sheet Author
API Scripter
This could be a job for the prefix trick from the stupid tricks thread, but yes, you could do this with a sheet worker. It seems like it would be really simple for a sheet worker, so I think I must be missing something. More specifics would probably help.  One thing to note: while in the character sheet this:  @{hth_parry}  is just text. Until its used in an autocalc field or a button is clicked, there's nothing special about it and you can break into parts and put it back together with basic string concatenation. A sheet worker could easily print take hth or hth2 and add it to parry, and wrap it in @{ } then print it to the sheet. If you have 10+ buttons, that all switch between hth and hth2, the simplest thing to do would be to have an array of the attribute names in the worker itself, and just construct them all whenever the combatskill value gets toggled. assuming you have an attrubute named 'strike', and you want it to include the text '@{hth_strike}' or '@{hth2_strike}', the worker would look something like this. on('change:combatskill', () => {     getAttrs(['combatskill'], values => {         const skills = ['strike', 'parry', 'dodge', 'etc'];         const output = {};         const combatskill = values.combatskill;         skills.forEach(skill => {             output[skill] = `@{hth${combatskill === '1' ? '' : combatskill}_${skill}}`;         });         setAttrs(output);     }); }); With more complete information, there might be a better way to do this.
1591405277
Kraynic
Pro
Sheet Author
I was going to use that substitution trick, but it wasn't working for me.  Which may very well have been a typo on my part somewhere...  So, I thought there was probably a sheetworker solution, but sheetworkers are still mostly a foreign language to me.  I'm about competent enough to alter things you have written for my use after I see where everything needs to plug in.  I'll probably work on it some more tomorrow. Just out of curiosity, as written would I need to change the attributes to the first hand to hand skill to be hth1_ to make it work?  I suppose it would at least be simpler (or make more sense) to have the number match instead of 1 being equal to a blank and 2 being equal to a number.
1591409385
GiGs
Pro
Sheet Author
API Scripter
The above sheet worker does account for it not being named hth1, but that would make the code simpler. My code above had an error, i fixed it. Give it another try.
1591409420

Edited 1591409530
GiGs
Pro
Sheet Author
API Scripter
And to be clear, combatskills is a radio button, with the values 1 and 2 hardcoded? If you do change the names to be hth1_, change this line output[skill] = `@{hth${combatskill === '1' ? '' : combatskill}_${skill}}`; to output[skill] = `@{hth${combatskill}_${skill}}`;
1592154863
Kraynic
Pro
Sheet Author
Sorry for not getting back to this to reply to your question.  I haven't even looked at the sheet over the last week due to not feeling well.  The toggle doesn't currently exist, so I can make it whatever.  Since the sheet hasn't been released to anyone, I can redo the attribute names of the first hand to hand section without any trouble.  Then if there are a bunch of people that need a third, it won't be hard to add, though I certainly hope that 2 is enough.