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

SetAbility HTML Replacers Help

1583281260
Dumbhuman
Pro
Marketplace Creator
I'm using Jakob's setAbility script ( code here ), but I'm running into a problem with HTML replacements.  This command: !setability --sel --replace --TestHTML#Bar|EndCurlyBrace} Results in this chat message: (From setAbility): Setting abilities Setting abilities TestHTML to Bar|EndCurlyBrace} for character Scenery. Which seems right, but the actual ability written on the character sheet is: Bar|EndCurlyBrace} Looking at the code, there's a function called htmlReplace, but the only other place that term shows up when searching the code is in the feedback section, which seems to logically explain why it reported the result I expected, but didn't actually write it to the ability.  Could someone with more coding knowledge than me (meaning, just about anyone) take a look at the code and give me a snippet to insert somewhere to make the functionality work, please?
1583469166
Dumbhuman
Pro
Marketplace Creator
If I had to take a blind guess, which I do, I'd think the call to the htmlReplace function gets inserted somewhere in the below code: parseAbilities = function (args, fillIn, replace) { return args.map(str => { let split = str.split('#'); return [split.shift(), split.join('#')]; }) .reduce((m, c) => { if (c[0] && c[1] !== undefined) { let str = c[1]; fillIn[c[0]] = str.search(/%%(\S.*?)(?:_(max))?%%/) !== -1; if (replace) { replacers.forEach(rep => { str = str.replace(rep[1], rep[0]); }); } m[c[0]] = str; } else if (c[0]) { m[c[0]] = false; } return m; }, {}); }, Am I warm, at least?  Without this puzzle piece falling into shape, I'm going to have to be stuck with creating dozens of abilities to be called in a button menu which I really would much rather avoid.
1583470443
GiGs
Pro
Sheet Author
API Scripter
Why are you using html replacements? I don't know if that's your issue here, but you need a very good reason to use html replacements around attribute calls. SetAbility has its own replacer characters to handle a lot of stuff, as described in the post you linked. I'm not sure what this is supposed to do !setability --sel --replace --TestHTML#Bar|EndCurlyBrace} Why do you have Bar and EndCurlyBrace typed out like that? Can you describe what you are trying to do, and maybe we can figure out how to do it without editing the code?
1583479080

Edited 1583551312
Dumbhuman
Pro
Marketplace Creator
The code provided was just an example that was supposed to illustrate that the htmlReplace function in the original setAbility code isn't being applied to anything other than the user feedback response.  I'm sure that was just an oversight on Jakob's part, because he refers to setAbility as a "hack" of ChatSetAttr, which itself does have functioning HTML replacements. Unfortunately, for a non-coder such as myself, the syntax between the two scripts differs entirely too much for me to easily see where to correct that oversight. The very good reason that I have for using HTML replacements around attribute calls is because I'm packing them into a roll query and thus can't leave the |'s and }'s unaltered without breaking the roll query and the attributes are only being written to the sheet with setAbility, not being called for immediate use.  If they get written without the HTML replacement happening though, then of course they're not going to function when the resulting ability is used. Perhaps this example will give you a better idea of what I'm doing: ?{Add Wild Shape stats for:         |Giant Rat, !setability {{ --sel --replace --silent --GiantRat#\p{WS|GiantRat} \new!token~mod ~~set currentside\h?{Which side to use for Giant Rat?} --NewWSButton# [Giant Rat](\til@{selected|druid_name}|GiantRat) }} |GiantOwl, !setability {{ --sel --replace --silent --GiantOwl#\p{WS|GiantOwl} \new!token~mod ~~set currentside\h?{Which side to use for Giant Owl?} --NewWSButton# [Giant Owl](\til@{selected|druid_name}|GiantOwl) }} } So if the user selects Giant Owl, it will prompt them with "Which side to use for Giant Owl?" and after receiving that input it will then write (or overwrite) two abilities on their character sheet, one called GiantOwl which should read (assuming they entered 3 as the side to use): %{WS|GiantOwl} !token-mod --set currentside#3 And another called NewWSButton which should read: [Giant Owl](~@{selected|druid_name}|GiantOwl) Currently though, without the htmlReplace function being called, those abilities would get written as: %{WS|GiantOwl} !token-mod --set currentside#3 And: [Giant Owl](~@{selected|druid_name}|GiantOwl) Yes, I know that technically I don't have to use a roll query format to present those options, because I could set them all up as separate abilities on the character sheet named WS (which I'm obviously already going to be referencing) and then provide a series of button menus, but I prefer the roll query method for this because it means writing just one additional ability rather than 80-something ability fields to cover all of the beasts and elementals from the SRD-OGL.  I imagine that a lot of text in a single ability field is lighter resource-wise than a similar amount of text spread among 80+ individual ability fields. In the end, in case it matters and isn't readily apparent, this is going to be part of a method for handling Druids' Wild Shape ability, but regardless of my ultimate goal, the problem I'd like help solving is the one presented in my original post: how can I get HTML replacement functionality properly working for setAbility?
1587488382
Dumbhuman
Pro
Marketplace Creator
I figure I'll add this challenge on top of the previous one, just in case anyone's feeling like exercising their coding skills. I'm trying to get a lot of mileage out of SetAbility right now, using it to basically rewrite a character sheet for a Druid's Wild Shapes so that I'll only need one extra character sheet per Druid instead of having lots of copies of beast forms.  In any event, one of the things I'd like to do is to have the ability to append extra text to an existing ability.  So for instance: !setability --sel --replace --WildShapes#[Ape](\p{WS|Ape}) Creates an ability called WildShapes which contains: [Ape](%{WS|Ape}) What I'd like is for script code to be added so that the following syntax: !setability --sel --replace --WildShapes#%WildShapes% [Axe Beak](\p{WS|Axe Beak}) Would result in an ability called WildShapes which contains: [Ape](%{WS|Ape}) [Axe Beak](%{WS|Axe Beak}) ChatSetAttr seems like it would be able to do that appending, but SetAbility currently can't.  I tried hacking in this bolded bit of code from ChatSetAttr into SetAbility in what seemed like the equivalent location (ParseAbilities compared to ParseAttributes), but it just crashes my sandbox, likely because I'm not a programmer and don't know what I'm doing: parseAbilities = function (args, fillIn, replace) { return args.map(str => { let split = str.split('#'); return [split.shift(), split.join('#')]; }) /* Find out if we need to run %_% replacement .map(([name, value]) => { if ((value.current && value.current.search(/%(\S.*?)(?:_(max))?%/) !== -1) || (value.max && value.max.search(/%(\S.*?)(?:_(max))?%/) !== -1)) value.fillin = true; else value.fillin = false; return [name, value]; }) Delete this above section if it breaks everything!! */ .reduce((m, c) => { if (c[0] && c[1] !== undefined) { let str = c[1]; fillIn[c[0]] = str.search(/%%(\S.*?)(?:_(max))?%%/) !== -1; if (replace) { replacers.forEach(rep => { str = str.replace(rep[1], rep[0]); }); } m[c[0]] = str; } else if (c[0]) { m[c[0]] = false; } return m; }, {}); }, The best I've been able to do on my own is add a few extra standard replacers, so I need help with how to properly add the %_% replacement functionality to SetAbility along with the HTML replacement stuff. Without the append functionality, the work around in my Wild Shape system is that every time a Druid character adds the stats for another Wild Shape, they have to manually copy and paste the appropriate button from a scratch ability before adding another (which then overwrites the scratch ability).  It would be much nicer to not have to worry about that step so that they could quickly just add as many forms as they want.