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

Setting the Show/Hide Description for NPC attacks

I virtually never want my players to see the attack descriptions for monsters, so I want to change the Show/Hide Description for NPC attacks.  Instead of modifying each monster/attack manually, I’d like to use either using an existing script or write my own. If it makes a difference, I have not switched this game over to Jumpgate.  It’s relatively close to the end and I'm waiting for the next campaign.  I would switch to Jumpgate if that would help anything.  I am also using the D&D 5E 2014 By Roll20 character sheet. I started out trying ChatSetAttr, but ran into an issue.  When I issue the following command in the chat, the option menu changes to Show, but the attack description itself (not just the option menu) also changes to the string “show”. !setattr --sel --repeating_npcaction_$1_show_desc|show So when I make the attack and roll the damage, the attack description is now simply the word “show”. When I issue a similar command with hide instead of show, the option menu does NOT change to Hide, but the attack description changes to the string “hide”.  The descriptive text (now just the word “hide”) still appears when I roll the damage.   So I decided to try my own script.  In the interest of full disclosure, my javascript is poor – it looks just like my C++ (which is pretty decent).  But I don’t think that’s my problem. Using getAttrByName() I am able to get at attributes like repeating_npcaction_$1_name and repeating_npcaction_$1_show_desc.  The latter returns “@{description}” which is what I see when I inspect the html. In order to change the values I tried using findObjs().  As a test, I tried the following to get and set the strength attribute: var strengthAttr = findObjs({    type: "attribute",    characterid: characterId,    name: "strength"  })[0];   if (strengthAttr) {    var strengthValue = strengthAttr.get("current");    log("Strength is: " + strengthValue); } strengthAttr.set("current", 25); This all worked fine, and I was able to modify the strength to 25.   When I try doing something similar for repeating_npcaction_$1_show_desc, I get an undefined returned. let secondActionAttr = findObjs({    type: "attribute",    characterid: characterId,    name: "repeating_npcaction_$1_show_desc"  })[0]; log("secondActionAttr is: " + secondActionAttr); This prints undefined. I’ve tried using repeating_npcaction_$1_name (which I can also get via getAttrByName) but I also get undefined.   When I inspect the html for the option menu I see: <select name="attr_show_desc">         <option value="@{description}" data-i18n="show">Show</option>         <option value=" " data-i18n="hide">Hide</option> </select> The Show option always has the “@description” even if the option menu is currently set to Hide.   All of this leads me to believe I don’t know what I’m doing, although I suspected that all along.   So my question is in two parts. (1) Am I using ChatSetAttr incorrectly? (2) In my script, how can I get the object for the Show/Hide option menu and set it to what I want? Even if someone can tell me what I’m doing wrong with ChatSetAttr, I’d still appreciate it if anyone could tell me what is wrong with my own script code. Thanks.   -- John
1764889942

Edited 1764911612
Edit with better solution:  Show an attack description: !setattr --sel --replace --repeating_npcaction_$0_show_desc|\at{description} Hide an attack description: !setattr --sel --replace --repeating_npcaction_$0_show_desc|' ' Does this NPC have more than one attack? Repeating sections start at $0, so you'll get 'undefined' if the character only has a single attack. The values for the 'show_desc' repeating attribute are not 'show' and 'hide'. They are '@{description}' and ' '. You can test this by manually changing the Show/Hide checkbox on the first attack of a creature and using this: /w gm @{selected|token_name} show_desc = @{selected|repeating_npcaction_$0_show_desc} Unfortunately chatsetattr cannot set a ' ' value here, as it is programmed to strip out any leading or trailing spaces. But there is a workaround: Show an attack description: !setattr --sel --replace --repeating_npcaction_$0_show_desc|\at{description} Edit: Hide an attack description: !setattr --sel --replace --repeating_npcaction_$0_show_desc|\at{description\|max} As a caveat, it looks like it won't change the visible dropdown to 'Hide', but it will prevent the description from displaying.  Edit: with a little more investigating, because ChatSetAttr is stripping out any leading or trailing spaces, you can modify the script to allow for a --replace feature. In the 'replacers' section at the top of the script, add this: [/\\space/g, " "], Mine currently looks like this because I've added replacement options for braces as well: replacers = [ [/<</g, "["], [/\\lbrak/g, "["], [/>>/g, "]"], [/\\rbrak/g, "]"], [/\\lbrace/g, "{"], [/\\rbrace/g, "}"], [/;/g, "?"], [/\\ques/g, "?"], [/`/g, "@"], [/\\at/g, "@"], [/~/g, "-"], [/\\n/g, "\n"], [/\\space/g, " "], ], Then you can use this command in chat and it will appropriately toggle 'Show' and 'Hide': !setattr --sel --replace --repeating_npcaction_$0_show_desc|\space
Thanks for the answer, Jarren. Yes, this NPC does have more than one attack.  When I make the following call you suggested, I actually get the attack description (not  '@{description}' or ' '). /w gm @{selected|token_name} show_desc = @{selected|repeating_npcaction_$0_show_desc} I thought I might have messed some things up with my script, so I tried it in a different game with the same results. I do get  '@{description}' or ' ' when I use getAttrByName() in a script with: let showDesc = getAttrByName(characterId, 'repeating_npcaction_$0_show_desc'); log(`NPC Show Desc: ${showDesc}`); The two calls to you suggested to !setattr to show/hide the description worked perfectly! Why does setting the attribute to ' @{description}|max' hide the description?  I don't understand that part. I haven't tried editing the ChatSetAttr code like you suggested yet.  I'm always hesitant to modify code I don't understand, although your mod is very simple. Many thanks. -- John
1764910489

Edited 1764911718
Edit with better solution:  Show an attack description: !setattr --sel --replace --repeating_npcaction_$0_show_desc|\at{description} Hide an attack description: !setattr --sel --replace --repeating_npcaction_$0_show_desc|' ' John  said: Thanks for the answer, Jarren. Yes, this NPC does have more than one attack.  When I make the following call you suggested, I actually get the attack description (not  '@{description}' or ' '). Yes, because of the Roll20 Order of Operations, when the 'show_desc' dropdown is set to 'Show', the value is set to '@{description} '. When the attribute is called with @{selected|repeating_npcaction_$0_show_desc}, it is replaced by @{description}, which is automatically parsed to @{CHARACTERID|repeating_npcaction_$0_description}, and then that is parsed to its value, which is the attack description. When the 'show_desc' dropdown is set to 'Hide', the value is set to ' ' and that's the output that you will see in chat with the macro. It's a little deceiving because the attribute you are calling is then calling a second attribute, and the contents of that second attribute are what is shown, which can lead you to believe that the attack description is directly in the 'show_desc' attribute, but it's not. The two calls to you suggested to !setattr to show/hide the description worked perfectly! Why does setting the attribute to ' @{description}|max' hide the description?  I don't understand that part. You could use almost any attribute on the character sheet. All legacy character sheets (so excluding new Beacon-based character sheets like the 'D&D 5e 2024 by Roll20' sheet) have a bunch of attributes, which are what was used on Roll20 before full character sheets were ever a thing. Back in the early days (before my time on Roll20) there were  only  attributes, but they could be used to basically customize an entire character sheet for stats manually. That system of attributes always includes a 'current' and 'max' value for any attribute that is created, and by default the 'max' value is always blank. I knew that 'show_desc' was a valid attribute for repeating actions, so I just reused it so that a blank value would be inserted into the 'current' value. It's not as good as using a space for the 'current' value, which is what the sheetworkers are looking for to determine whether the dropdown menu should display as 'Hide'. That's why updating ChatSetAttr to allow for a 'space' substitution actually works to change the dropdown to 'Hide'. When the value of 'show_desc' is a space, then the dropdown shows as 'Hide'. When the value of  'show_desc'  is not a space, then the dropdown shows as 'Show'. I haven't tried editing the ChatSetAttr code like you suggested yet.  I'm always hesitant to modify code I don't understand, although your mod is very simple. I went back and looked at a  similar question  and was able to come up with this use of ZeroFrame that will work with the existing ChatSetAttr code to change to 'Hide': !setattr {{  --sel  --replace  --repeating_npcaction_$0_show_desc|spacer  }} {&global ([spacer]  )} Or with a little more testing... there's an even easier solution built into ChatSetAttr. You can use single quotes to add a space value: !setattr --sel --replace --repeating_npcaction_$0_show_desc|' ' I tried a bunch of times using doublequotes and that was putting the quotes into the attribute, but I didn't consider using single quotes until right now. /facepalm
That all actually makes sense to me.  I've never had to get into the Roll20 Order of Operations for the few things I've done so far.  Thanks for the explanation. I tested it and it both show/hid the descriptive text and also changed the option menu. How many collective hours do you think have been spend on " vs ' ?  I think the answer would be horrifying. Cheers -- John