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

How do I get API-commands and Macros to work in order?

Hello there, English isn't my first language, so I apologize if the grammar is a bit off. Me and my party are employing a couple of custom rules and I have a problem with the following: Our initiative-order is an attribute value called 'Initiative' +1d6, which simply determines the turn order. Additionaly, Initiative is rolled against a difficulty, and for each point the player rolls above said difficulty, he also gains one extra d6 for later actions. Example: A Charakter with an Initiative of 3 rolls a 5 against a diffculty of 4. His Initiative is now 8 and he gains 4 extra d6 for later actions. So, we need an output of two different values: 1d6+attribute for initiative-order and 1d6+attribute-difficulty for extra dice. My first attempt to put this in a macro looks like this: @{Name} rolls for initiative /r {{[[1d6cs>1cf0+@{initiative}]]-?{difficulty|0|1|2|3|4|5|6}}, {1d0}}d1 extra dice gained Now, this DOES work, but it looks like crap. I then went over to using the the ChatSetAttr API-Script for a different approach, working through two attributes in namend "ini" and "diff" in the character sheet: !setattr --name @{name} --diff|[[?{difficulty|0}]] --silent !setattr --name @{name} --ini|[[1d6+@{initiative}]] --silent &{template:default} {{name=@{name} rolls for Ini:}} {{Initiative=[[@{ini}]]}} {{extra dice=[[@{ini}-@{diff}]]}} This looks just as I want it to, but the template executes before the API has changed the attributes, meaning it uses the values from the LAST roll instead of the current one. Is there ANY way to "tell" the template to wait for the API changing the attributes and THEN execute? I took from an older thread that a !delay command from the Store_Command script could be a workaround, but that script crashes my sandbox when I implement it (no longer compatible?).
1518339331
GiGs
Pro
Sheet Author
API Scripter
You might be better off writing a short API script of your own for handling this, and printing out the result. You can use html to format the output, so you can have it looking however you want.
1518354650

Edited 1518359133
Hi G G, I spent the bigger part of last night trying to solve the problem and got to the same conclusion :-) Now, I DID get the Store_Commands script to work (to anyone with the same problem: You have to have the SplitArgs script from the library installed first. It's clearly stated in the wiki, but if you're a noob like me...), but it seems that "all" that it does, is give you the RESULTS of the stored commands in a certain order but still execute them all at once (it is still a super awesome script, though. My many thanks to the author!). I'm not anywhere near to being a programmer, so better take the following conclusion with mountainous amounts of salt, BUT as far as I've understood the logic of roll20 in general, it would seem that: a) all macros and API commands are ALWAYS executed at once (or as fast as possible, for that matter) and options like roll templates and such can only format the RESULTS and b) macros and API commands can (out of the box) not reference themselves, hence I cannot make a dice roll and then tell the system to take the result and create several different outputs with that result. Any experienced programmer may feel free to correct me if I'm wrong =) So, in conclusion, the initiative roll system I came up with for my campaign hooks into the exact two things roll20 urrently can't do. Horray me... Also, if I wanted any system that needs one or both of the above mentioned functionalities, I would have to create an API script that works these things completely outside of roll20's own logic and then brings the results back in afterwards.(Again: I'm not much as a programmer, don't take this as a fact!) Time to learn some java script ;) I guess... of course, if any of the authors feels like takling the problem, you'd probably be faster at it than me ;-)
1518355238
GiGs
Pro
Sheet Author
API Scripter
With an API script, you can do everything within the script. You can have it roll the dice, manipulate the dice however you desire (assign the result to initiative roll, calculate the bonus dice, and store those 2 results separately), then build an output string, formatting it like html, and finally print the formatted results to chat. It can be done. The language is javascript btw, not java - they are two very different languages.
1518357590

Edited 1518357767
GiGs
Pro
Sheet Author
API Scripter
Here's a quick and dirty script for you to try. Create a new script in the API-Scripts section, name it initiative (or whatever) and paste this in. Save it. Instructions for use are in the first few lines of the script. /* Call this as follows (create an Ability on a character sheet with this text): !custom-init [[1d6+@{initiative}]] ?{difficulty|0|1|2|3|4|5|6} Be careful! you must have "!custom-init" followed by a space then the initiative roll followed by a space then the difficulty. You can make this more generic: !custom-init [[1d6+@{selected|initiative}]] ?{difficulty|0|1|2|3|4|5|6} You can save this as a global macro, visible to All Players, set as a token action, and it's available to everyone who has a token. And you can hardcode the initiative or the difficulty !custom-init [[1d6+4]] 2 */ on('ready',function(){     'use strict';     var getSpeaker = function(msg) {         var characters = findObjs({_type: 'character'});         var speaking;         characters.forEach(function(chr) { if(chr.get('name') == msg.who) speaking = chr; });               if(speaking) return 'character|'+speaking.id;         else return'player|'+msg.playerid;     };          on('chat:message',function(msg){         if('api' === msg.type && msg.content.match(/^!custom-init/)  ){              let args = msg.content.split(/\s+/);             let diff = args[2];             if(msg.inlinerolls === undefined) { //msg.inlinerolls sendChat("Initiative","No Initiative Roll Detected"); return; }; if (isNaN(diff)) {                 sendChat("Initiative","No Difficulty Value Detected"); return;             } let init = msg.inlinerolls[0].results.total; let bonusDice = Math.max(0,init-parseInt(diff)); let outPut = '&{template:default} {{name=Initiative Roll}} {{Initiative='+init+'}} {{Bonus Dice='+bonusDice+'}}';             sendChat(getSpeaker(msg),outPut);         }     }); });
Dude, you are officially on my list of awsome people. Thank you so much! The language is javascript btw, not java - they are two very different languages. ... aaaand probably saved me a ton of time there :-D
1518361040
GiGs
Pro
Sheet Author
API Scripter
You're welcome :)
1518421008

Edited 1518453719
The Aaron
Pro
API Scripter
Just for clarity, the chat commands are all handled on the client in order, but the result of an api command is sending a request off to the api server (basically...), and it’s response comes back with some delay, which is why you get the output out of order. 
Hi Aaron, That's good to know, thanks for the clarification. Concluding from that, would getting the client to "idle" a bit possibly be a workaround to the problem, i.e. creating a macro that takes the client more time to put out than a simple dice roll? Greetings from Germany
1518453708
The Aaron
Pro
API Scripter
Much easier to just send things you want to happen after the API command to the API, or to trigger them separately, possibly with a whispered button.  You couldn't guarantee the execution woudl be in the correct order, otherwise.
1518453760
The Aaron
Pro
API Scripter
( Greetings from Indianapolis, Indiana, USA!)
1518458931
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
The Aaron said: ( Greetings from Indianapolis, Indiana, USA!) Geez, I forgot. Gen Con is just a stroll across town for you.