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

Macro that reads current face of Rollable Token

1641942122

Edited 1641942355
MAMS Gaming
Pro
Sheet Author
Everything I've found in my search talks about using API to change the face of a Rollable Token, but I can't find anything that checks what the face currently is. I have a rollable table with the names "d4" "d6" "d8" "d10" and "d12". I want a macro that rolls the die of whatever face the token is currently set to.
1641943421
timmaugh
Pro
API Scripter
Don't think that is available short of through a script, either. Fetch is a metascript that will return it for you, and you can use that value in another api, or (with ZeroFrame) a standard chat message or an inline roll. @(selected.currentside) @(Simeon.currentside) @(@{target|Target|token_id}.currentside) @(Bob the Hirsute.currentside[default value here]) All work. You can get the number of sides from the "sides" property: @(selected.sides) Here it is in a simple chat message (using ZeroFrame, too): !@{selected|token_name} is currently set to @(selected.currentside).{&simple} REQUIRED SCRIPTS: Fetch, ZeroFrame (optional)
1641948674
MAMS Gaming
Pro
Sheet Author
That sounds great. I tested it though, and it doesn't seem to be working. Sure, when I plug in your example, it prints to chat just fine, but I can't seem to figure out any syntax that makes it work in my macro. Even just a simple Macro like: &{template:default} {{name=@{selected|token_name} }} {{**Token ID**= @{selected|token_id} }} {{**Bar 3**= @{selected|bar3} }} {{**Side**= @(selected|currentside).{&simple} }}
1641953153
timmaugh
Pro
API Scripter
If you're going to use scripts, even just to output a simple chat message, you have to send the message to the API first... start with an exclamation point (to send it the API), then include {&simple} somewhere in it (to kick the message back to chat). That means your example should look something more like: !&{template:default} {{name=@{selected|token_name} }} {{**Token ID**= @{selected|token_id} }} {{**Bar 3**= @{selected|bar3} }} {{**Side**= @(selected|currentside)}}{&simple}
1641955871

Edited 1641956141
MAMS Gaming
Pro
Sheet Author
Awesome. Thanks for walking me through this. That simple Macro worked, but it looks like I'm not done yet. I started putting it into my Custom Roll Template, and the exclamation point breaks it. !&{template:scrpg} {{name=@{selected|token_name}}} {{suffix= - @{selected|bar1}}} {{die1-d@{selected|bar3}=1}} {{r1name=d@{selected|bar3} = }} {{roll1=[[d@{selected|bar3}cs>13cf<0]]}} {&simple} My roll template has: {{#die1-d4}}     {{#rollTotal() roll1 1}}...{{/rollTotal() roll1 1}}     {{#rollTotal() roll1 2}}...{{/rollTotal() roll1 2}}     {{#rollTotal() roll1 3}}...{{/rollTotal() roll1 3}}     {{#rollTotal() roll1 4}}...{{/rollTotal() roll1 4}} {{/die1-d4}} {{#die1-d6}}...{{/die1-d6}} etc. and the ! seems to make it skip those sections. once I get that working, the next step will be to replace @{selected|bar3} with 12-@(selected|currentside)*2
1641958267
timmaugh
Pro
API Scripter
Hmm. I wonder if this is because your final output message comes from the API... so you don't have selected tokens, your playerid, or who sent the message in the message object. Maybe your roll template needs one or more of those to do what it does. The way to get around that is to install one more metascript: SelectManager. Without going too into the weeds on what SelectManager does, it addresses the exact problem I just described. As far as whether the problem I described is the problem you are having... we'll have to see. Install SelectManager. It will come preconfigured to give back the selected tokens to an API-generated message. To see what is currently configured, run: !smconfig The selected tokens might be enough to correct your issue, so test your macro. If it doesn't work, configure SelectManager to also give back the playerid using the below command: !smconfig +playerid Then test your macro again. If THAT doesn't work, configure SM to give back the "who": !smconfig +who To turn any of those off again, just replace the + with a -.  Hopefully one of those will solve your issue, but post back if it does not.
1641959684

Edited 1641965170
MAMS Gaming
Pro
Sheet Author
Nope, still nothing. It occurs to me: Does it matter that I'm using a sandbox for this? My roll template doesn't require any of those, but as you can see, the Macro does require selected. The other times that same data was sent from the selected to the Macro, it showed up though, which is why I pointed out that specific part of the template. If you're curious to check the Template yourself, it just got merged to Roll20 today: <a href="https://github.com/Roll20/roll20-character-sheets/blob/master/Sentinel%20Comics%20RPG/SCRPG-Sheet.html" rel="nofollow">https://github.com/Roll20/roll20-character-sheets/blob/master/Sentinel%20Comics%20RPG/SCRPG-Sheet.html</a> Edit: It did not matter that it was a Sandbox. I tried it in a normal game, and got the same result.
1641995290
timmaugh
Pro
API Scripter
Couple of clarifications... the @{select|...} Roll20 calls resolve immediately in the line, so they won't require selected tokens in the message object. Typically the kind of access to the selected token that causes problems (with regard to API-generated messages) is if the outbound script (so, where Script #1 calls Script #2, we're talking about Script #2) uses the set of selected tokens to look up its own information (things not resolved in the command line). I didn't know if that was happening with your custom roll template. This could be an odd interaction with the metascripts and the way you have your roll template set up, but that just gives me an opportunity to improve Fetch.&nbsp; The roll-template/sheetworker stuff isn't my forte, but I know just the man for the job. *opens the Summonomicon * *begins muttering the incantations of page 14, "Summoning the Greater Scott"*
1642112264
MAMS Gaming
Pro
Sheet Author
Well, I got my macros working effectively, but I worry that they are a little fragile. When I "Spawn" the tokens, I define bar3 with a number to reference the side (w/out max, so no bar shows up). When I "Token-Mod" to change the side, I also change that number in bar3. When I finally use the roll macro, I reference bar3 to tell me which side is showing. It's not ideal, as someone could change bar3, or manually change side instead of using my Token-Mod macro, which would throw them out of synch. If you and Scott (the Great &amp; Powerful) figure out what caused the API to break my Template, I'd love to be able to "Fetch" the side and the statusmarker. Thanks again for your help!
1642138564
MAMS Gaming
Pro
Sheet Author
I just thought of something weird in the code of my roll template that might mess with other code. It uses one &lt;/div&gt; to end 4 potential &lt;div&gt; {{#color-Red}} &lt;div class="sheet-rfill sheet-scrpg-desc"&gt; {{/color-Red}} {{#color-Yellow}} &lt;div class="sheet-yfill sheet-scrpg-desc"&gt; {{/color-Yellow}} {{#color-Green}} &lt;div class="sheet-gfill sheet-scrpg-desc"&gt; {{/color-Green}} {{^color-Red}}{{^color-Yellow}}{{^color-Green}} &nbsp;&nbsp;&nbsp;&nbsp;&lt;div class="sheet-outfill sheet-scrpg-desc"&gt; {{/color-Green}}{{/color-Yellow}}{{/color-Red}} ... &nbsp;&nbsp;&nbsp;&nbsp;... &nbsp;&nbsp;&nbsp;&nbsp;... &lt;/div&gt; Could this be interfering with anything? If so, I could add the conditions for ending the div to match the ones that start the div.
1642165576
timmaugh
Pro
API Scripter
That could be interfering, sure. I haven't done a ton with the Character Sheet side of things to say for sure. Can you post your full roll template code so we can see what you have going on? And, is there a reason you only have the one DIV?
1642177862
MAMS Gaming
Pro
Sheet Author
I did post my roll template above. Actually, it's a link to the whole html of the sheet in the roll20 database. I think I can save you from looking through my code though, as I spent time putting simple text in-between each set of brackets to figure out what was being ignored, and I found it. {{roll1=[[1d6]]}} ... {{#rollTotal() roll1 1}}Ignored Code Here{{/rollTotal() roll1 1}} {{#rollTotal() roll1 6}}Ignored Code Here{{/rollTotal() roll1 6}} It's a code within roll templates that only triggers when the roll result = X. (1 and 6 on these lines respectively)
1642183659
timmaugh
Pro
API Scripter
Excellent!
1642291207
MAMS Gaming
Pro
Sheet Author
Do we have a verdict yet? Will it be possible to have Fetch pass that information back to the roll template? One trick that we have to use when sending data from a macro to a template with this "rollTotal()" check, is that it has to be inline. If I try to pass {{roll1=6}} it won't recognize it, but if I pass {{roll1=[[6]]}} it thinks it's a roll, and triggers the {{#rollTotal() roll1 6}} script. Does that help?
1642431763

Edited 1642431785
timmaugh
Pro
API Scripter
Sorry, I thought your previous post indicated that you'd solved the problem. Let me look at the template and see if I can figure out what's going on. I think Scott is intending to weigh in on this when he gets a chance, too, and he is much better with the sheet workers and sheet templates than I am. I am fairly confident that we can get you where you want to be... I just have to understand where to plug in the various steps.
There was a broadly similar use-case request ( naming tokens for their rollable table labels ) a few years ago, for which TheAaron wrote a script . Maybe something in his code can be usefully adapted here.
1642884097
MAMS Gaming
Pro
Sheet Author
Lady Victoria said: There was a broadly similar use-case request ( naming tokens for their rollable table labels ) a few years ago, for which TheAaron wrote a script . Maybe something in his code can be usefully adapted here. That looks awesome. It might have the code I'm looking for. Also, I've been having trouble understanding Aaron's code, so having a short snippet like this will be easier to dissect, and learn his syntax. Thank you on both counts.
1643073716
MAMS Gaming
Pro
Sheet Author
Okay, I'm going to call this solved. I know it would have been faster to do this if Fetch was able to handle roll Templates that look at the result of a roll, but since it couldn't, I made my own API to just make this one roll. Once I realized that&nbsp;token.get('currentSide') was an API command, the rest fell into place pretty quickly. on('ready',function(){ "use strict"; var handleInput = function(msg) { if ((msg.content.indexOf("!rollbyface") !== -1 ) &amp;&amp; (msg.selected)) { for (let i = 0; i &lt; msg.selected.length; i++) { let token = getObj("graphic", msg.selected[i]._id), token_name = token.get('name') || 'Minion Roll', speaker = 'player|'+msg.playerid, diesize = 'd'+(12-token.get('currentSide')*2), imgs=_.map(token.get('sides').split(/\|/),(i)=&gt;{return i;}); if (imgs.length != 5) {return}; //sendChat(speaker,'&amp;{template:default} {{name='+token_name+'}} {{'+diesize+'=[['+diesize+'cs&gt;13cf&lt;0]]}}'); sendChat(speaker,'&amp;{template:scrpg} {{name='+token_name+'}} {{die1-'+diesize+'=1}} {{r1name='+diesize+' = }} {{roll1=[['+diesize+'cs&gt;13cf&lt;0]]}}'); }; }; &nbsp;&nbsp;&nbsp;&nbsp;}; on('chat:message', handleInput); });