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

[Help for a code] Display message in the chat

1754121370

Edited 1754200833
Maïlare
Pro
Sheet Author
API Scripter
Hello, I have a problem with my code that I can't figure out. When the script sends the message in the chat, it's supposed to be shown only to the GM. But Roll20 divides my message into several parts, like in the image below, so it's displayed to all players. Does anyone have a solution because I can't see what's wrong with my code? My code is available here :&nbsp; <a href="https://github.com/Roll20/roll20-api-scripts/blob/master/Calendar%20and%20Weather/Calendar%20and%20Weather.js" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/blob/master/Calendar%20and%20Weather/Calendar%20and%20Weather.js</a>
1754138599
Gauss
Forum Champion
Hi Mailare, You mentioned an image but there isn't one in your post.
1754200871
Maïlare
Pro
Sheet Author
API Scripter
Hi Gauss,&nbsp; I have modified it
1754202145
Gauss
Forum Champion
Thanks, I am not an API Scripter but now someone who is can see what is going on. :) My guess though, whatever you are sending to the chat is not being added to the first line you are sending to chat.&nbsp; For example:&nbsp; If I do this (macro template):&nbsp; /w GM &amp;{template:default} {{name=Test}} {{item1=object1}} {{item2=object2}} Then it will all be together But if I do this instead:&nbsp; /w GM &amp;{template:default} {{name=Test}} {{item1=object1}} {{item2=object2}} Then I have made an oopsie, and item2=object 2 will be on another line, and not sent to GM.&nbsp; I would look at whatever kind of API Script output code keeps it all together.&nbsp;
1754204108

Edited 1754204270
Maïlare
Pro
Sheet Author
API Scripter
Thanks for your comment, but I don't think it's this. The mod are developped in javascript and it's not the same syntax of the macros. And all my html output variables are coded with the good syntax. W hether I write "html =+" to add data to the variable or "html =" and write the contents of the variable on several lines will give the same result in the end. the contents of the variable "html" will be what I wrote there on a single line.
1754205544
Gauss
Forum Champion
I was providing an constrasting example, as I said, I don't code API Scripts.&nbsp; I was hoping to provide you a broad idea of a direction to check.&nbsp; Hopefully an API Script writer will take a look and be able to help.
1754205932

Edited 1754205993
Maïlare
Pro
Sheet Author
API Scripter
Yes, no problem, I have understand this, it's why I explain you how the javascript syntax works ;). I hope too an other API script writer can help me, it's maybe a little mistake but I don't see it.
1754227247
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Is it all messages that the script sends? Or only some of them? And if it's only some, which ones and what line(s) in the code are the send chat calls for those messages?
1754250826
Maïlare
Pro
Sheet Author
API Scripter
Hello Scott,&nbsp; This is for all messages except for weather reports (the one for the GM and the one for the players). But I might have a clue, the messages that are causing problems all have buttons. And for your second question, the relevant code is located from line 281 to line 349.
1754255494
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I believe that your issue is caused by using the &lt;br&gt; html. IIRC, the chat parser doesn't like that. But it's been a while since I did a lot of API scripting. Instead of using &lt;br&gt; use inline css to lay your section out. Alternatively, you are using divs like they are spans. divs are block elements. Since it looks like you are using these for inline display, I'd recommend just using a span.
1754290643
Maïlare
Pro
Sheet Author
API Scripter
I did the test on the showGMMainMenu part and it's better, all the content is displayed in a single message, but still in a second message and still not only to the GM.
1754298808
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Wrap the entire sendChat content (minus the /w gm) in a containing div. line breaks shouldn't be an issue inside of that.
1754306832
Maïlare
Pro
Sheet Author
API Scripter
Hello keithcurtis, This is already the case, I tested by modifying the code as Scott suggested but despite that, the message is always sent in two parts. A first message whispered to the GM and another that the players can see. It's annoying, it overloads the chat for the players.
1754323779

Edited 1754323951
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
So, the message that is output by the buildFullWeatherReportHTML function does not show the issue? That made me remember a display issue that occurs when there are new lines between the end of one div and the start of another. For some reason the chat has issues with this and splits them up. So, taking your gm menu as an example, if you change it to be this: const showGMMainMenu = () =&gt; { const s = state.WeatherMod; const climates = Object.keys(WeatherConfig.climates).map(climate =&gt; `&lt;a style="${btnStyle}" href="!weather setgm climate ${climate}"&gt;${climateIcons[climate]} ${tClimate(climate)}&lt;/a&gt;` ).join(" "); const html = `&lt;div style="${chatStyle}"&gt;` +`&lt;div style="${styleTitle}"&gt;${t('weather')}&lt;/div&gt;${hr}` +`&lt;div style="${styleSection}"&gt;${t('climate')}:&lt;/div&gt; ${climateIcons[s.selectedClimate]} ${tClimate(s.selectedClimate)}&lt;br&gt;` +`${btnGroup(climates)}${hr}` +`&lt;div style="${styleSection}"&gt;${t('language')}:&lt;/div&gt; ${s.language.toUpperCase()}&lt;br&gt;` +`${btnGroup(`&lt;a style="${btnStyle}" href="!weather lang en"&gt;EN&lt;/a&gt; &lt;a style="${btnStyle}" href="!weather lang fr"&gt;FR&lt;/a&gt;`)}${hr}` +`${btnGroup(`&lt;a style="${btnStyle}" href="!weather menu-date"&gt;📅 ${t('date')}&lt;/a&gt;`)}` +`${btnGroup(`&lt;a style="${btnStyle}" href="!weather menu-manual"&gt;🛠 ${t('manual')}&lt;/a&gt;`)}` +`${btnGroup(`&lt;a style="${btnStyle}" href="!weather menu-profiles"&gt;💾 ${t('profiles')}&lt;/a&gt;`)}` +`${btnGroup(`&lt;a style="${btnStyle}" href="!weather report"&gt;🌦 ${t('generate')}&lt;/a&gt;`)}` +`${btnGroup(`&lt;a style="${btnStyle}" href="!weather showplayers"&gt;📣 ${t('weather')} → Players&lt;/a&gt;`)}` +`&lt;/div&gt;`; sendChat("WeatherMod", `/w gm ${html}`); }; You will eliminate the new lines between the end and beginning of divs, and the menu will output correctly. Making that change, results in this output: EDIT: Had erroneously used += instead of + in the string creation.
1754338032
Maïlare
Pro
Sheet Author
API Scripter
Thanks a lot Scott. It's working. I will remember this if I create an other mod, it's an issue specific to Roll20. I think I don't have see anything about this on the wiki, it will be a good thing to add this.
1754344293
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
That's pretty much what I meant, all the returns contained within a single div for each sendChat instance as in&nbsp; ${html} . I just didn't have the time at Gen Con to deeply dip into your code.
1754458564
Maïlare
Pro
Sheet Author
API Scripter
No problem keithcurtis, I don't have understand your answer like this but with the explanation of Scott it's good :D
1754468376
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
As long as it works. :D