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] Using Anchor tags to customize API command buttons in chat

I want to use sendChat() to provide API command buttons that have backgrounds and specific styling.   I've found lots of posts that lead me to believe this is all possible, but I cannot find the wiki pages that explicitly explain it.  This level of specific use gets muddled for me because it seems like I have to combine a bunch of different Syntax styles that I'm not entirely familiar with. To have a background image in chat (like a roll template) does that have to be defined in the character sheet CSS?  Do I still need the thumbnail imgsrc url for such backgrounds?
1546695454

Edited 1546695510
GiGs
Pro
Sheet Author
API Scripter
If you're using an API script, there are two ways to do it: You can embed a call to an actual rolltemplate, but you need to structure your scripts output to match it. e.g. starting the text output with &{template:whataver} and using the rolltemplates structure for your output, eg {{name=whatever}}. That's the simplest approach. If the rolltemplate isn't enough, you can build your own template, using the full range of html tags including tables and grids, applying styles using style=, like  <span style="font-weight:bold">some text</span>. You have to define everything you need in the script, including imgsrc, yes.
1546697158
The Aaron
Pro
API Scripter
Just to add to that, when you output the image in a style or img tag, it doesn’t need to be in a user library. It can be pretty much any url you want. However, you may want to put it in a user library just to be sure it is stable.  You can use most CSS in inline styles, but there are some tags that will get filtered (it’s a white-listing system). Most function-style CSS3 modifiers won’t work (like translate() and skew()), though url() does. You’ll likely need to spend a good deal of time outputting messages to chat and inspecting them for what styles they retained.  You may find you need to specify some styles just to remove a particular behavior. Case in point, I had a devil of a time getting the small card images in PeekCard working right, until I noticed all img tags on Roll20 have a default of “min-width: 100px” or similar. When I’m working on formatting the output from a script, I’ll often get the pieces in the right hierarchy, then manually edit the styles in the browser via the developer tools until it looks right, then copy them back into the script.  Hope that helps!
1546781929

Edited 1546784949
Thank you both I'll give that a try.  ***edit** Some of my initial confusion came from misinterpreting another post.  I thought it implied that I could feed raw HTML to the chat to create a background image.  Now I realize that it was all in the roll template.  
1546788736
GiGs
Pro
Sheet Author
API Scripter
You can feed raw html to the chat with a script. A rolltemplate does that too.
1546792047
The Aaron
Pro
API Scripter
If you look Mutant Year Zero , it does a lot of work with putting images on the background and such.
Wow, that's a beautiful display.  Your code is too advanced for me too understand quickly.  I'm trying to do something far simpler to start.  I want to create a stylized list of api command buttons to respond to questions during a guided character creation dialogue. I'm starting with this:   sendChat("Announcer","(type '!next' to progress or click: [Next](!next)") Through cannibalizing roll templates I have something like this:  sendChat("Announcer", '&{template:ythos1} {{name=Next Button}} {{button1=[Next](!next)}}') And that displays a normal API command button. I just have to figure out how to style it.  Alternatively I was trying this in a roll template and a sendChat()  (most of the styling is just leftover from cannibalization): <a href="!next" style= "border:0px; background-repeat:no-repeat; background-size:100% 100%; background-color:transparent; background-position:center; color:black; padding:10px 20px 10px 30px">Next</a> But I'm not sure how to format the href so that it actually displays a command button.  The place I cannibalized from used <<COMMAND>> for the href, but that didn't seem to work for me either. I've got a pretty hodge-podge, trial and error learning style here.  I feel like I'm getting closer, just missing something basic.
1546796750

Edited 1546796780
The Aaron
Pro
API Scripter
Something like this: sendChat("Announcer", `<div style="font-size:.8em; background-color: #eee; border: 1px solid #666; padding: .5em; border-radius: .5em;">(Type <code>!next</code> to progress or click: <a style="background-color: #aaffaa ; display: inline-block ; border: 1px solid #888 ; color: black ; border-radius: 10px ; font-weight: bold ; padding: 1px 10px" href="!next">Next</a></div>`); Will give you:
Thanks again Aaron.
1546799317
The Aaron
Pro
API Scripter
Taking it to the next level, you could do this: const message = (contents) => `<div style="font-size:.8em; background-color: #eee; border: 1px solid #666; padding: .5em; border-radius: .5em;">${contents}</div>`; const command = (cmd) => `<code>${cmd}</code>`; const button = (cmd, label, color='#aaffaa') => `<a style="background-color: ${color}; display: inline-block ; border: 1px solid #888 ; color: black ; border-radius: 10px ; font-weight: bold ; padding: 1px 10px" href="${cmd}">${label}</a>`; /* ... */ sendChat("Announcer", message(`(Type ${command(!next)` to progress or click: ${button('!next','Next')}`)); That lets you reuse the button easily, and the message, and change the formatting in only one place.
1546802551
GiGs
Pro
Sheet Author
API Scripter
const button = (cmd, label, color='#aaffaa') All this time on roll20 learning javascript and I hadnt realised you could set default values like that. If I had that as a declration, and called button with, say,  sendChat("Announcer", message(`(Type ${command(!next)` to progress or click: ${button('!next','Next','red')}`)); would it override the color in the const declaration? is it valid to do that?
1546805312
The Aaron
Pro
API Scripter
It absolutely would.  Don't feel too bad, the default value syntax is relatively new to Javascript and the API.  Probably has only worked on Roll20 for less than a year.
1546805466
The Aaron
Pro
API Scripter
The fat arrow functions and modern syntax really let you make some great abstractions.  I've switched to this for my showHelp formatting  (See it in the latest version of Bump): const _h = { outer: (...o) => `<div style="border: 1px solid black; background-color: white; padding: 3px 3px;">${o.join(' ')}</div>`, title: (t,v) => `<div style="font-weight: bold; border-bottom: 1px solid black;font-size: 130%;">${t} v${v}</div>`, subhead: (...o) => `<b>${o.join(' ')}</b>`, minorhead: (...o) => `<u>${o.join(' ')}</u>`, optional: (...o) => `${ch('[')}${o.join(` ${ch('|')} `)}${ch(']')}`, required: (...o) => `${ch('<')}${o.join(` ${ch('|')} `)}${ch('>')}`, header: (...o) => `<div style="padding-left:10px;margin-bottom:3px;">${o.join(' ')}</div>`, section: (s,...o) => `${_h.subhead(s)}${_h.inset(...o)}`, paragraph: (...o) => `<p>${o.join(' ')}</p>`, group: (...o) => `${o.join(' ')}`, items: (o) => `<li>${o.join('</li><li>')}</li>`, ol: (...o) => `<ol>${_h.items(o)}</ol>`, ul: (...o) => `<ul>${_h.items(o)}</ul>`, grid: (...o) => `<div style="padding: 12px 0;">${o.join('')}<div style="clear:both;"></div></div>`, cell: (o) => `<div style="width: 130px; padding: 0 3px; float: left;">${o}</div>`, inset: (...o) => `<div style="padding-left: 10px;padding-right:20px">${o.join(' ')}</div>`, pre: (...o) =>`<div style="border:1px solid #e1e1e8;border-radius:4px;padding:8.5px;margin-bottom:9px;font-size:12px;white-space:normal;word-break:normal;word-wrap:normal;background-color:#f7f7f9;font-family:monospace;overflow:auto;">${o.join(' ')}</div>`, preformatted: (...o) =>_h.pre(o.join('<br>').replace(/\s/g,ch(' '))), code: (...o) => `<code>${o.join(' ')}</code>`, attr: { bare: (o)=>`${ch('@')}${ch('{')}${o}${ch('}')}`, selected: (o)=>`${ch('@')}${ch('{')}selected${ch('|')}${o}${ch('}')}`, target: (o)=>`${ch('@')}${ch('{')}target${ch('|')}${o}${ch('}')}`, char: (o,c)=>`${ch('@')}${ch('{')}${c||'CHARACTER NAME'}${ch('|')}${o}${ch('}')}` }, bold: (...o) => `<b>${o.join(' ')}</b>`, italic: (...o) => `<i>${o.join(' ')}</i>`, font: { command: (...o)=>`<b><span style="font-family:serif;">${o.join(' ')}</span></b>` } }; Used thusly: const showHelp = (playerid) => { const who=(getObj('player',playerid)||{get:()=>'API'}).get('_displayname'); sendChat('',`/w "${who}" `+ _h.outer( _h.title('Bump', version), _h.header( _h.paragraph('Bump provides a way to invisibly manipulate tokens on the GM Layer from the Objects Layer, and vice versa.') ), _h.subhead('Commands'), _h.inset( _h.font.command( `!bump-slave`, _h.optional( `--push`, `--help` ) ), _h.paragraph( 'Adds the selected tokens to Bump, creating their slave tokens.'), _h.ul( `${_h.bold('--push')} -- If the selected token is on the Objects Layer, it will be pushed to the GM Layer.`, `${_h.bold('--help')} -- Shows the Help screen.` ), _h.font.command( `!bump`, _h.optional( `--help` ) ), _h.paragraph( `Using !bump on a token in Bump causes it to swap with it${ch("'")}s counterpart on the other layer.`), _h.ul( `${_h.bold('--help')} -- Shows the Help screen.` ) ), _h.subhead('Description'), _h.inset( _h.paragraph('When a token is added to Bump a slave token is created that mimics everything about the master token. The slave token is only visible to the GM and has a color on it to show if the master token is on the GM Layer or the Objects layer. Moving the slave token will move the master token and vice versa. The slave token represents the same character as the master token and changes on the slave token will be reflected on the master token.'), _h.paragraph('Non-GM players can also use bump on characters they control. They will be able to see their bumped token as a transparent aura, but other players will not. This is useful for invisible characters.'), _h.paragraph(`While changes on the slave token will be reflected on the master token, Status Markers have a special behavior. Status Markers are always cleared from the slave token to prevent it from being visible, with the following changes being made to the master token. Adding a Status Marker on a slave token that is not on the master token will cause that Status Marker to be added to the master token. Adding a Status Marker to the slave token that is on the master token causes it to be removed from the master token. Adding a Status Marker with a number on the slave token will cause that number to be added to the master token${ch("'")}s Status Marker. Note that non-GM players will not be able to see Status Markers.`) ), ( playerIsGM(playerid) ? _h.group( _h.subhead('Configuration'), getAllConfigOptions() ) : '' ) ) ); };
1546817846
GiGs
Pro
Sheet Author
API Scripter
I've been using a method from one of your older scripts for styling text, but if I can wrap my head around this, it does look powerful.
1546823842
The Aaron
Pro
API Scripter
Each function takes some arguments, fits them into a string and returns it.  Then it's just a bunch of nesting functions.  Let me know if you have any questions. =D