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

JS Mod/API: Other Than a Roll Query, Is There Another Way to Paste Text That Can Be Used?

1787193778

Edited 1787193991
Advanced D&D 1e Character sheet values but I think this applies to any character sheet. When I want to change a field value in a character sheet without the user having to open the character sheet, I set up a procedure to type in or paste the text the user wants into a roll query entry. Pasting text into a roll query does not preserve line breaks, unfortunately, and I really want to discourage players from using the character sheet. I use this code which is similar to that I use in some other different roll queries in my scripts:         let nameQuery = "?{Enter or copy/paste your new " + fDesc + " or leave blank to delete all of it. " + "Make sure you have no hyphens, vertical bars, or braces or you're gonna have a bad time" + "|" + "}"; let nameCommand = "!checkblanks" + " --" + charID + " --" + opt + " --" + fDesc + " --" + nameQuery; let nameButton = btn( "Enter or Copy/Paste Text", nameCommand, 5); Procedure !checkblanks has these arguments: charID is the character ID; opt is possible options (not relevant here); fDesc in this case, is standing for "Character History"; and nameQuery is the roll query into which a player will typically paste large amounts of text or possibly just type in short place names or what have you. The procedure !checkblanks massages the result of nameQuery (replaces { } and things with ASCII or HTML labels) and warns user of they have an empty - blank - string. It then passes the "massaged" result of nameQuery to another procedure which uses the mod library chatattr !setattr statement from Jakobto to plop it into a character sheet field using these lines where charID is the character ID of the character in question and character_description is the biography of the character:             let commandvalue = `!setattr --charid ${charID} --character_description|${fPaste}`; sendChat("", commandvalue); This has been working really beautifully  EXCEPT  when it comes to line breaks. The roll query is not designed to deal with breaks. So if I want to paste the following (in bold) with the indicated line break: This dwarf is from the Glittergold clan where he learned fighting skills. He has worked at Luke Ratif's Mill 3 miles NE of Northtown for 2 years. When I go through the above, I end up with the following in the field: This dwarf is from the Glittergold clan where he learned fighting skills. He has worked at Luke Ratif's Mill 3 miles NE of Northtown for 2 years. I am wondering if there is any other place besides a roll query into which I can paste text without using a roll query? I was hoping to avoid using it, but I guess if ScriptCards is the only option, I'll have to get to work. Thanks. :-)
1787198398
Gauss
Forum Champion
What happens when you put the line breaks in the form of html entities or newline commands? 
1787241751

Edited 1787242921
The Aaron
Roll20 Production Team
API Scripter
If I understand correctly, you have a construct something like: !api-command ?{query} And query could have a bunch of line breaks pasted into it.  The script gets the first line, and the following lines show up as chat? If that is the case, you can handle it with a bit of hackery by structuring the command like this: !api-command {{?{query}}} Then strip the {{ }} out of the chat message the API gets. Something like this should get you what you want: let content = msg.content.replace(/(\{\{(.*?)\}\})/g," $2 ");
1787303669

Edited 1787309231
The Aaron said: If I understand correctly, you have a construct something like: !api-command ?{query} And query could have a bunch of line breaks pasted into it.&nbsp; The script gets the first line, and the following lines show up as chat? Not quite; that sort of thing was happening when I was bringing character sheet text with line breaks into a chat result: Keith helped me with that sort of thing here: <a href="https://app.roll20.net/forum/post/12775198/break-in-a-character-sheet-field-makes-that-field-break-outside-of-sendchat-chat-box" rel="nofollow">https://app.roll20.net/forum/post/12775198/break-in-a-character-sheet-field-makes-that-field-break-outside-of-sendchat-chat-box</a> &nbsp; I ended up using this as a global for any fields that could have line breaks I bring from the character sheet: TimGlobals.cleanQueryText = function cleanQueryText(text) { return (text || "") .replace(/(?:\r\n|\r|\n)/g, "&lt;br&gt;") .replace(/\|/g, "&amp;#124;") .replace(/\{/g, "&amp;#123;") .replace(/\}/g, "&amp;#125;") .replace(/--/g, "—"); }
Gauss said: What happens when you put the line breaks in the form of html entities or newline commands?&nbsp; It works when I pop in &lt;br&gt; which is nice. Perhaps I'll just put in an advisory to do that and leave it. :-) Thanks.