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 .
×

Recreating a Char Box used in an API/Mod?

1778464119

Edited 1778531160
I may have made this too long and complicated - reposted in a simpler post - I hope! :) Rats That should be "Chat Box". Good grief. This is a longish question with images and a macro snippet and an API/Mod snippet. I think &nbsp;what I'm asking is relatively simple though. From my understanding, if I have created an API which would modify the entries in a chat template the macros uses, then I&nbsp; cannot &nbsp;call the API using commands in the macro (unless they are buttons - I have numerous macros using tokenmod, for example as buttons). Is that correct? I have a macro for saves. It's for AD&amp;D 1e, but I don't think that matters for this question. The macro runs the following, whispered to the player who runs the macro: /w @{selected|character_name} &amp;{template:general} {{color=@{selected|color_option}}} {{name=@{selected|character_name}}} {{subtag=Saving Throws}}{{ *Ask DM: Does Dex Bonus Count?* }} {{Saving Throw Notes ``@{selected|savingthrow_notes}`` Magic Resistance Notes ``@{selected|magic_resistance}``}} {{ [Paralysis/Poison/Death](~selected|saveparalysispoisondeath) [Petrification/Polymorph](~selected|savepetrificationpolymorph) [Rods/Staves/Wands](~selected|saverodsstaveswands) [Breath Weapons](~selected|savebreathweapons) [Spells](~selected|savespells) }} &amp;{noerror} It produces a chat tab result which works well: However, there are 3 items I wanted to tailor to the player: dexterity bonus/penalty (if any) and Saving Throw Notes "@{selected|savingthrow_notes}" and Magic Resistance Notes "@{selected|magic_resistance}" in the above macro. My API/Mod script follows. It has considerable things commented out that I used to develop it. takes the arguments dex, st, or mr to calculate dex bonus, saving throw notes or magic resistance notes. You can just skip to "//Tim - dealing with output", about halfway through:&nbsp; //10 May 2026 Based on what I originally made for a Crossfire dice script in. //Initial dealing with what a token is from a Google inquiry (AI response to "roll20 API get selected character" ) //For AD&amp;D 1e Character sheet //Function is !dexcheck and it outputs: // dexterity saving throw bonus/penalty, argument dex; // saving throw notes, argument st; or // magic resistance notes, arhument mr. on('ready', () =&gt; { //Version information const ver = "Version 1" const verdate = "10 May 2026" //The following will be outputted after a restart sandbox or save: log("═╣ Dex Check for Saving Throw by Tim, " + ver + ", " + verdate + " ╠═"); //Tim - From here to the next Tim comment is from AI response to "roll20 API get selected character" on("chat:message", function(msg) { let chatcommand = msg.content.trim().toLowerCase(); if (msg.type === "api" &amp;&amp; chatcommand.indexOf("!dexcheck") === 0) { if (!msg.selected) { sendChat("System", "---------"); sendChat("System", "Please select a token first."); return; } // Map through selected items to find character objects let characters = msg.selected .map(obj =&gt; getObj('graphic', obj._id)) // Get the token object .filter(token =&gt; token &amp;&amp; token.get('represents') !== "") // Check if it represents a character .map(token =&gt; getObj('character', token.get('represents'))); // Get the character object // Do something with the first selected character if (characters.length &gt; 0) { let character = characters[0]; let checkresult = ""; let checkoutput=""; sendChat("System", "---------"); //sendChat("System", "Selected Character: " + character.get("name") + " " + characters.length); //Tim crap now - let's get dexterity bonus &amp; notes for some saving throws //sendChat("System", "Char ID: " + character.id); //sendChat("System", "Saving Throw Bonus: " + getAttrByName(character.id,"armorbonus")); //sendChat("System", "Saving Throw Notes: " + getAttrByName(character.id,"savingthrow_notes")); //sendChat("System", "Magic Resistannce Notes: " + getAttrByName(character.id,"magic_resistance")); //The following was originally done with single quotes for !dexcheck, but works fine with double quotes let checktype = chatcommand.replace("!dexcheck","").trim(); //sendChat("System", "checktype: " + checktype); //Tim - dealing with output if (checktype === "dex") { //sendChat("System", "checktype command is for dexterity"); //sendChat("System", "Saving Throw Bonus: " + getAttrByName(character.id,"armorbonus")); checkresult = getAttrByName(character.id,"armorbonus"); if (checkresult == "0") { checkoutput = "No possible dexterity bonus/penalty."; } else if (parseFloat(checkresult) &lt; 0) { checkoutput = "**Dexterity**: Check with DM if your " + checkresult + " bonus applies."; } sendChat("System", checkoutput); return; } else if (checktype === "st") { //sendChat("System", "dexcheck checktype is saving throw notes"); //sendChat("System", "Saving Throw Notes: " + getAttrByName(character.id,"savingthrow_notes")); checkresult = getAttrByName(character.id,"savingthrow_notes"); if (checkresult == "") { checkoutput = "**Saving Throw Notes**: N/A"; } else { checkoutput = "**Saving Throw Notes**: " + checkresult; } sendChat("System", checkoutput); return; } else if (checktype === "mr") { //sendChat("System", "dexcheck checktype is magic resistance notes"); //sendChat("System", "Magic Resistannce Notes: " + getAttrByName(character.id,"magic_resistance")); checkresult = getAttrByName(character.id,"magic_resistance") if (checkresult == "") { checkoutput = "**Magic Resistance Notes**: N/A"; } else { checkoutput = "**Magic Resistance Notes**: " + checkresult; } sendChat("System", checkoutput); return; } else { //sendChat("System", "After writing **dexcheck** you must add a space and include: **dex** for dexterity bonus; **st** for saving throw notes; or **mr** for magic resistance notes."); checkresult = ""; sendChat("System", checkoutput); return; } } } }); }); Which, with the sendChats, reliably results in the following for 2 different characters, depending on the argument used: So, going back to macro result: I would like to replace: "Ask DM: does dexterity count" with !dexcheck dex; "Saving Throw Notes" and any results with !dexcheck st; and "Magic Resistance Notes" and any results with !dexcheck mr. So... It appears the above three things, the "checkoutput" variable in the If statement, cannot be added to the macro. I need to figure out how to do the macro in an API. Unfortunately, the section on doing this is not helpful to me at my level of knowledge. :( <a href="https://help.roll20.net/hc/en-us/articles/36003726754-API-Chat#API:Chat-ChatEvents" rel="nofollow">https://help.roll20.net/hc/en-us/articles/36003726754-API-Chat#API:Chat-ChatEvents</a> Are there any other tutorials or articles out there that can help? Thank you if you are still with me. :) -- Tim
Rats, I think I made this way too complicated for anyone to bother with.