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 .
×

Break in a Character Sheet Field Makes That Field Break Outside of sendChat Chat Box

1782563552

Edited 1782681192
Solved! Use the following replace in the script:           let spellDesc = getAttrByName( bCharID, `repeating_spells_${bspellID}_spell_description` ) || ""; spellDesc = spellDesc.replace(/(?:\r\n|\r|\n)/g, '<br>'); -------------------------------------------------------------------------------------------------- Apologies for posting again. The title might be confusing so I thought I'd illustrate what is happening. The character sheet I am using is for Advanced Dungeons & Dragons 1e. Again, the sheet works fine for me but I'm trying to make navigating it easier for my computer illiterate friends so that they don't have to scroll through it to find stuff. This has to do with displaying the description field of a spell by a spell caster. 1) Here is what is a screenshot of a player's 1st level spells. The details for the spell Phantasmal Force are opened. You can see the description beginning with "When this spell is cast..." 2) Here is a screenshot of the above spell details in the sendChat window I've scripted. The two words highlighted are where a line break (enter key) will be placed: 3) So, back to the character sheet. You can see where the line break has been entered as compared to 1, above: 4) And this is how the above affects the chat window. You can see that the text after the line break, AKA the second paragraph, appears outside the chat window and below: So I think that illustrates my issue. I'm hoping there's a solution. Here are the code snippets involved in the script. 5) This one shows how I am drawing the description from the character sheet.  spellDesc , highlighted, is obtained using getAttrByName. The spell identifier, bspellID, is the spell's ID code: 6) The above and other spell characteristics, if they are not zero length strings,  are added to a variable called bspellBody, highlighted below. bspellBody will be the spell description text shown in 2 and 4, above: 7) bspellBody is then given to the sendChat shown below which uses a formula, panel (modified from ROTTO's code from the Vince's 1e sheet group), to create the chat box: My Attempts So, going back to the screenshot at 6, above. I have enclosed the spellBody with <p>: bspellBody += "<p>" + spellDesc + "</p>"; This does not have any effect. I've tried enclosing it in a <div>:                 bspellBody += "<div style='text-align:left;padding: 2px 0;'>"; bspellBody += spellDesc; bspellBody += "</div>"; And this does not work, either. The Panel function I mentioned encloses bspellBody (as the variable  body ): '<div style="background:#efe3cf;color:#1b1712;padding:3px;border-radius:6px;">' + body + '</div>' + Note that it already encloses bspellBody in a <div>, anyway I'm not sure if the above line can be altered to avoid the line break(s) from appearing outside the chat box or not. Any suggestions? I'm OK to leave the "malfunction" as it is, to be honest, but it would be nice to have it all enclosed in the sendChat chat box.  Thanks. PS FWIW, this is the "flow" from an admin screen to the spell information. A lot of players don't bother to put anything in the spell info, which is fine. The image in the Spells List is one of a couple dozen based on whether the user is an MU/Illjusionist, Cleric, or Druid spell caster. The MU spells and the cantrips, and second level spells are just  test things.
1782584141
vÍnce
Pro
Sheet Author
I know these are necessary for API output, but it looks like you can easily get something mixed up with all the embedded HTML/CSS and string literals...  Make sure bSpellBody is not initialized as a const.  Apply KISS whenever possible.  I would start by injecting spellDesc into bSpellBody (within the div).  Wrap spellDesc within a <p> but forgo any inline styling just to help eliminate possible typos/malformed HTML/CSS.
vÍnce said: I know these are necessary for API output, but it looks like you can easily get something mixed up with all the embedded HTML/CSS and string literals...  Make sure bSpellBody is not initialized as a const.  Apply KISS whenever possible.  I would start by injecting spellDesc into bSpellBody (within the div).  Wrap spellDesc within a <p> but forgo any inline styling just to help eliminate possible typos/malformed HTML/CSS. Thank you Vince. I tried all that with unfortunately the same results. Discovered that line breaks are a vulnerability in all my scripts like this one that presents equipment.  Here, the contents of a chest is separated from the rest of the description by line breaks. Has to be something, somewhere interpreting line breaks. I had related problems many years ago in using MS Access (which all our maintenance staff and other university departments had) to format reports from my  Oracle database and had to run some code to convert how the line breaks were dealt with. I had to run some code in the MS VBA stuff to convert all line breaks. With that in mind, I googled line breaks in html and tried, without success:      <br> in the character sheet field - interestingly, the character sheet removed these after closing it     double space and enter     backslash before the enter I will leave this for now as is and later delve deeper into scriptcards to see if I can remedy it. Now back to trying to deal with the hideous slowness of the Roll20 mod/API engine when left idle for a little while.
1782665017
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
How about the HTML entity for a line break instead of <br>? 
 for paragraph break 
 for newline
1782681078

Edited 1782681307
keithcurtis said: How about the HTML entity for a line break instead of &lt;br&gt;? &amp;#13; for paragraph break &amp;#10; for newline Hi Keith, thanks. I will use those breaks in some instances. I've solved my issue: <a href="https://stackoverflow.com/questions/784539/how-do-i-replace-all-line-breaks-in-a-string-with-br-elements" rel="nofollow">https://stackoverflow.com/questions/784539/how-do-i-replace-all-line-breaks-in-a-string-with-br-elements</a> . I used the first response in that 17 yo thread. See the replace statement after extracting the character sheet text using getAttrByName: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let spellDesc = getAttrByName( bCharID, `repeating_spells_${bspellID}_spell_description` ) || ""; spellDesc = spellDesc.replace(/(?:\r\n|\r|\n)/g, '&lt;br&gt;'); The problem was that line breaks in the character sheet fields I inserted into a sendChat would not be included in the sendChat out put. See 3 and 4 in my OP. With the replace described in the first response in the above link, I did not have that problem any more. This is the sendChat result now that is 4 in my OP: The next screenshot was where I noticed this first, with the MU of a group. It had two breaks, all of which following the first appeared outside the sendChat output. Now all safely ensconced inside: I found the&nbsp;&amp;#13; and&nbsp;&amp;#10; characters you suggested would restrict the break to be like one would find in a book, i.e, not double spaced.
1782699587
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Depending on the CSS the roll template uses, paragraph space might be hard-coded. If so,&nbsp;&amp;#13; should have covered it. But it might also just be a double return, in which case&nbsp;&amp;#13;&amp;#13; might have worked. But it sounds like you have a solution!
1782700119
timmaugh
Pro
API Scripter
Also, if you're looking to create line breaks, the Metascript Toolbox can help with that.
keithcurtis said: Depending on the CSS the roll template uses, paragraph space might be hard-coded. If so,&nbsp;&amp;#13; should have covered it. But it might also just be a double return, in which case&nbsp;&amp;#13;&amp;#13; might have worked. But it sounds like you have a solution! Yeah, delighted with it. Thanks. timmaugh said: Also, if you're looking to create line breaks, the Metascript Toolbox can help with that. Interesting, thanks. I see reference to that thread in your and Aaron's selectmanager. I wonder if that would have saved my death cry and startling my parrots (my wife is visiting family in the US) when I started seeing the issue? LOL