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

Question about inline rolls and API

September 16 (10 years ago)
Paul S.
Sheet Author
API Scripter
Ok - so I'm wanting to inline roll a table in API. I can "/roll 1t[whatever]" but that gives wonky output in the chat window.

To further complicate things, I'd like to include the inline roll result in fancy formatted box:

Ultimate goal is a really basic weather script that has VERY generic temp generation and a daily weather forecast (implementing fancy icons for the weather result is also on my list).

So far I've got temperatures for 4 seasons of a more-or-less temperate climate. Might think about adding the ability to differentiate on climate later. Here's the code:
on('chat:message', function (msg) {
    var range, min;
        if (msg.type == 'api' && msg.content.indexOf('!summer') !== -1) {
            range = 55;
            min = 60
            var x = Math.floor(Math.random() * range) + min;
            sendChat(
                '', 
                "/direct "
                +"<div style='"
                    +'background-color: #4B0082;'
                    +'border: 3px solid #808080;'
                    +'font-size: 20px;'
                    +'text-align:center;'
                    +'vertical-align: top;'
                    +'color: white;'
                    +'font-weight:bold;'
                    +'padding: 5px 5px;'
                +"'>"
                    +"The current temperature is: "+x+" degrees"
                +"</div>"
            );
        }
        if (msg.type == 'api' && msg.content.indexOf('!winter') !== -1) {
            range = 55;
            min = -20
            var x = Math.floor(Math.random() * range) + min;
            sendChat(
                '', 
                "/direct "
                +"<div style='"
                    +'background-color: #4B0082;'
                    +'border: 3px solid #808080;'
                    +'font-size: 20px;'
                    +'text-align:center;'
                    +'vertical-align: top;'
                    +'color: white;'
                    +'font-weight:bold;'
                    +'padding: 5px 5px;'
                +"'>"
                    +"The current temperature is: "+x+" degrees"
                +"</div>"
            );
        }
        if (msg.type == 'api' && msg.content.indexOf('!fall') !== -1) {
            range = 40;
            min = 30
            var x = Math.floor(Math.random() * range) + min;
            sendChat(
                '', 
                "/direct "
                +"<div style='"
                    +'background-color: #4B0082;'
                    +'border: 3px solid #808080;'
                    +'font-size: 20px;'
                    +'text-align:center;'
                    +'vertical-align: top;'
                    +'color: white;'
                    +'font-weight:bold;'
                    +'padding: 5px 5px;'
                +"'>"
                    +"The current temperature is: "+x+" degrees"
                +"</div>"
            );
        }
        if (msg.type == 'api' && msg.content.indexOf('!spring') !== -1) {
            range = 40;
            min = 30
            var x = Math.floor(Math.random() * range) + min;
            sendChat(
                '', 
                "/direct "
                +"<div style='"
                    +'background-color: #4B0082;'
                    +'border: 3px solid #808080;'
                    +'font-size: 20px;'
                    +'text-align:center;'
                    +'vertical-align: top;'
                    +'color: white;'
                    +'font-weight:bold;'
                    +'padding: 5px 5px;'
                +"'>"
                    +"The current temperature is: "+x+" degrees"
                +"</div>"
            );
        }
}
);
September 16 (10 years ago)
The Aaron
Roll20 Production Team
API Scripter
So, what's the question?

You can add a 3rd parameter to sendChat() which is a function that receives the expanded output of the chat message including the inline rolls (if the 3rd parameter is used, nothing goes to the chat.). You can send it inline table rolls: [[1t[some-table] ]]

Does that help?
September 16 (10 years ago)
Paul S.
Sheet Author
API Scripter
I'll try sending a third parameter. Didn't know about that. I was attempting to add inline rolls within the <div> in the above code and it wasn't working. I was getting results $[[1... Or something similar. Same with normal /roll statements.

So, very generally, for the three parameter sendChat, the format for this would be sendChat(who, "text", "/roll"); ?
September 16 (10 years ago)
Lithl
Pro
Sheet Author
API Scripter
No, the three parameters are sendChat(who, message, function(ops) { ... });
September 16 (10 years ago)
Paul S.
Sheet Author
API Scripter
Ok. I now get what I have to do to make this work (after studying the power card script and he wiki page on crit rolls). In the end, I'm going with power card script being fed info from rollable tables. Not as elegant, but I already had powercard script active anyway.