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

Format Strings Sent to Chat Window?

May 06 (12 years ago)
Konrad J.
Pro
API Scripter

How would you go about formatting a variable and a string in the sendChat command?

            sendChat("", i + " Performs a Drift Right -D1 to Handling");

Also can you add an enter in the formatting so that some of the text is on a 2nd line?

May 06 (12 years ago)

Just do a second sendChat command maybe?

May 06 (12 years ago)
Alex L.
Pro
Sheet Author

Or \n ie:

sendChat("", i + " Performs a Drift Right -D1 to Handling \nThis will be on a new line.");
May 06 (12 years ago)

Just fyi, you cannot use the \n in a whisper. It creates an entirely new line visible to everyone like normal chat.

May 06 (12 years ago)
Alex L.
Pro
Sheet Author

HoneyBadger said:

Just fyi, you cannot use the \n in a whisper. It creates an entirely new line visible to everyone like normal chat.

Good to know.


May 06 (12 years ago)
Riley D.
Roll20 Team

In the first example, keep in mind that if you're wanting to put "someone does something" you probably want to make use of the first argument to sendChat which you are leaving as a blank string, e.g. sendChat("Riley", "/em Throws a tomato!"); would automatically put "Riley throws a tomato" formatted as an emote. 

So if you want to "format" things, first off, try and take advantage of the built-in commands when possible (e.g. "/em", "/desc", "/ooc", "/w", etc.)

Secondly, think of sendChat() the same as using a Macro in-game, the same rules will be applied. So a newline indicates a separate command...you could do sendChat("Riley", "/w Greg Hello there \n /w Greg How are you?"); You just have to be sure to repeat the /w command on the newline as well. Likewise you could put an emote and a roll, etc.

May 06 (12 years ago)
Alex L.
Pro
Sheet Author

An chance we could get a way to output directly to the chat window and bypass all the auto formatting (ie auto repeat name after x lines) and maybe get a little bit of formatting of our own like background colour text colour and bold?

This would make things like command help lists far more clear.

May 06 (12 years ago)
Riley D.
Roll20 Team

Alex L. said:

An chance we could get a way to output directly to the chat window and bypass all the auto formatting (ie auto repeat name after x lines) and maybe get a little bit of formatting of our own like background colour text colour and bold?

This would make things like command help lists far more clear.

Perhaps. I'll consider it.

May 06 (12 years ago)

I tried that and it didn't work. It just appeared as Greg How are you? I'll try it again though.

May 06 (12 years ago)
Alex L.
Pro
Sheet Author

Riley D. said:

Alex L. said:

An chance we could get a way to output directly to the chat window and bypass all the auto formatting (ie auto repeat name after x lines) and maybe get a little bit of formatting of our own like background colour text colour and bold?

This would make things like command help lists far more clear.

Perhaps. I'll consider it.
Thanks very much. I know its be requested about 10 times in other parts of the forums before so i thought i would bring it up.


May 06 (12 years ago)
Riley D.
Roll20 Team

HoneyBadger said:

I tried that and it didn't work. It just appeared as Greg How are you? I'll try it again though.

Actually it's possible you may have to make sure there isn't a space after the \n. So "/w Greg Test \n/w Greg Test2".

May 06 (12 years ago)

Oh yeah... that would be what did it.

May 06 (12 years ago)
Konrad J.
Pro
API Scripter

Riley D. said:

In the first example, keep in mind that if you're wanting to put "someone does something" you probably want to make use of the first argument to sendChat which you are leaving as a blank string, e.g. sendChat("Riley", "/em Throws a tomato!"); would automatically put "Riley throws a tomato" formatted as an emote. 

So if you want to "format" things, first off, try and take advantage of the built-in commands when possible (e.g. "/em", "/desc", "/ooc", "/w", etc.)

Secondly, think of sendChat() the same as using a Macro in-game, the same rules will be applied. So a newline indicates a separate command...you could do sendChat("Riley", "/w Greg Hello there \n /w Greg How are you?"); You just have to be sure to repeat the /w command on the newline as well. Likewise you could put an emote and a roll, etc.

I was looking in the API docs, it snever occured to me to look in the regular chat docs. :) Doh!

Thanks guys!!!

May 28 (12 years ago)
Konrad J.
Pro
API Scripter

Riley D. said:

Alex L. said:

An chance we could get a way to output directly to the chat window and bypass all the auto formatting (ie auto repeat name after x lines) and maybe get a little bit of formatting of our own like background colour text colour and bold?

This would make things like command help lists far more clear.

Perhaps. I'll consider it.
Have you considered this anymore?  :)  I can get by without it, but it would help if I could turn off the regular formatting and then put different colour text or background, bold, italics, etc.  I've got a script for the Edge of Empire Dice.  They have six different coloured dice.  I would be nice to colour the background or the text the colour of the dice in question. :)

May 28 (12 years ago)

Honestly, if I were going to run/play Edge of the Empire Star Wars... I'd use that google hangout app specifically made for it.

May 28 (12 years ago)
Alex L.
Pro
Sheet Author

HoneyBadger said:

Honestly, if I were going to run/play Edge of the Empire Star Wars... I'd use that google hangout app specifically made for it.

Good for you, some of us would rather just use roll20.


May 28 (12 years ago)
Konrad J.
Pro
API Scripter

HoneyBadger said:

Honestly, if I were going to run/play Edge of the Empire Star Wars... I'd use that google hangout app specifically made for it.

Ya, but then you have to be in Google hangouts.  Which isn't bad, jsut saying.  You don't have to be a mentor to use the google hangouts thing either so thats an advantage if you aren't paying.  But then I wouldn't be having any fun devising this script.

And guess what Riley just gave us the ability to do....Not sure if its possible to overlay images, I tried but not successful, don't really know HTML very well yet.  But if not possible then I just have an image for every possible dice side and we have our own Roll20 dice for Edge of the Empire complete with dice graphics.


May 28 (12 years ago)

Any implementation of EotE dice in Roll20 are going to be awkward and it will slow down the pace of the game. Using the hangout app specifically made for EotE dice is a far superior way to play the game imo. You can still use Roll20 in the hangout and have the EotE hangout app open to the right of Roll20.

At least until we have a way to create new UI elements in Roll20. Then you can create something that would actually work as well as the hangout app.

May 28 (12 years ago)
Konrad J.
Pro
API Scripter

Hmm, not sure why it would slow down the pace.  Same as rolling dice.  And the dice would be recorded in the chat log as well.  simple command !r 1b 3y 1r

Boom you get the pictures of the dice right in the chat window.  I've got it working right now, just not with pictures yet.

And I don't even play the game, someone just requested it and I thought it would be another good way to learn the API and what it can do.  If we don't push it to the limits we won't see all the crazy stuff its capable of. :)

May 28 (12 years ago)

I have enough problems with players remembering what their attack bonuses are in D&D 4e and that's a simple /r 1d20+x command... let alone getting them to remember what all the chat command options are for an EotE game. A visual dice roller like the hangout app is a far superior way to run the game for players of all levels of competency, imo.

May 28 (12 years ago)
Konrad J.
Pro
API Scripter

OK.  But the dice mechanics are simpler in some ways with EotE.  The player has a pool of dice, the GM tells them how many dice to add to this pool.  So its 1 blue, 1 yellow and two red.  then you just type in !r 1b 1y 2r.  But yes the google hangout app is nice and better in most ways.

May 28 (12 years ago)
Alex L.
Pro
Sheet Author


AS of this moment you can sort of create new UI but its a huge hack and im not going to go into how you do it as i expect it to be removed very soon.

May 28 (12 years ago)
Riley D.
Roll20 Team

Alex L. said:


AS of this moment you can sort of create new UI but its a huge hack and im not going to go into how you do it as i expect it to be removed very soon.

Haha...hmmm...did you do that with Javascript or strictly CSS?

May 28 (12 years ago)
Alex L.
Pro
Sheet Author

Riley D. said:

Alex L. said:


AS of this moment you can sort of create new UI but its a huge hack and im not going to go into how you do it as i expect it to be removed very soon.

Haha...hmmm...did you do that with Javascript or strictly CSS?
All CSS but i could do it with javascript :P

I have destroyed 5 test campaigns messing around with this stuff so far.

using Campaign.characters.get(id) then view.showDialog() i have worked out how to open a char sheet up on the client :P Oh and ajax one way only atm but im working on it.

Do you regret giving me html yet?

Edit: scratch that I have fully working two way ajax and the ability to get the selected token.
May 29 (12 years ago)
Riley D.
Roll20 Team

Alex L. said:

Riley D. said:

Alex L. said:


AS of this moment you can sort of create new UI but its a huge hack and im not going to go into how you do it as i expect it to be removed very soon.

Haha...hmmm...did you do that with Javascript or strictly CSS?
All CSS but i could do it with javascript :P

I have destroyed 5 test campaigns messing around with this stuff so far.

using Campaign.characters.get(id) then view.showDialog() i have worked out how to open a char sheet up on the client :P Oh and ajax one way only atm but im working on it.

Do you regret giving me html yet?

Edit: scratch that I have fully working two way ajax and the ability to get the selected token.
Regret? No, but I will have to lock it down more... :P

May 29 (12 years ago)
Riley D.
Roll20 Team

Okay, so, I've added some further sanitization. In general, things I'm okay with you doing with this direct HTML access:

  • Doing basic formatting with the style attribute, adding <strong>, <em>, etc.
  • Adding elements such as <img> tags, <divs>, etc., including styling and external images. At some point in the future these may be restricted to only images hosted on Roll20. I realize that this does open up a vector currently where you could load an "img" with a src that is really a GET request to an outside service...so maybe that needs to be changed. I dunno, for now I'm going to leave it since there's no easy way to access the URLs of your uploaded images. But I wouldn't count on this staying for too long.
Things I'm not okay with:
  • Any execution of arbitrary Javascript whatsoever. If there are still vectors allowing this after this latest update (which should have shored up things like putting javascript: links in <a> tags) please let me know so I can continue to shore it up.
  • Two-way AJAX requests...again you can abuse the <img> tags right now to do GET requests which may need to be fixed, but you definitely shouldn't be able to load in outside data and use it in the app.
You might send me a PM with examples of what you're doing so I know what I'm missing :-)

EDIT: Oh, also, I fixed the scripts editor so now if you have HTML in the editor it won't cause the editor to not load.
May 29 (12 years ago)
Alex L.
Pro
Sheet Author

Riley D. said:

Okay, so, I've added some further sanitization. In general, things I'm okay with you doing with this direct HTML access:

  • Doing basic formatting with the style attribute, adding <strong>, <em>, etc.
  • Adding elements such as <img> tags, <divs>, etc., including styling and external images. At some point in the future these may be restricted to only images hosted on Roll20. I realize that this does open up a vector currently where you could load an "img" with a src that is really a GET request to an outside service...so maybe that needs to be changed. I dunno, for now I'm going to leave it since there's no easy way to access the URLs of your uploaded images. But I wouldn't count on this staying for too long.
Things I'm not okay with:
  • Any execution of arbitrary Javascript whatsoever. If there are still vectors allowing this after this latest update (which should have shored up things like putting javascript: links in <a> tags) please let me know so I can continue to shore it up.
  • Two-way AJAX requests...again you can abuse the <img> tags right now to do GET requests which may need to be fixed, but you definitely shouldn't be able to load in outside data and use it in the app.
You might send me a PM with examples of what you're doing so I know what I'm missing :-)
EDIT: Oh, also, I fixed the scripts editor so now if you have HTML in the editor it won't cause the editor to not load.
You look to have fixed all my arbitrary javascript execution points, I will have a look later and see if I can break it any more.
I notice you still have css in there I would suggest limiting or even abstracting the CSS as you can make the app unusable very easily. The biggist culprites for this would be position, although it lets me make a UI without JavaScript that UI is pointless so you may as well fillter out the position related stuff before someone works out how to make a Phishing script.
May 29 (12 years ago)
Konrad J.
Pro
API Scripter

Riley, it really must be a bit depressing that in this world we have to worry about things like this, but it is reality I guess.  Its good Alex was able to find all this stuff though!!!

If you get rid of external images, which I think is probably a good idea, we really need to have a way to easily get at the images in a campaign still.  I can inspect the elements and find the paths, but it makes any script based on that a lot harder for regular users to use. :(

May 29 (12 years ago)
Alicia
Sheet Author

You could assign the path as a variable at the beginning which the user could then change when needed. This makes the code a bit cleaner as well.
The same could be done for each of the image names.

May 29 (12 years ago)
Konrad J.
Pro
API Scripter

Alicia G said:

You could assign the path as a variable at the beginning which the user could then change when needed. This makes the code a bit cleaner as well.
The same could be done for each of the image names.

Yup, they will all be variables so the user can choose whatever graphics they like for the script.  But the internal file names are all using random letters and numbers type naming.  It doesn't keep the original file name.  So you have to manually inspect for each file. :(