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

Using Fetch & Zeroframe to return the total number of sides for a rollable token

I'm trying to simply display the number of sides a rollable token has (it's for a Scenes token that I add new images to periodically). Here's my command: !/w gm @(selected|character_name) image has a total of @(selected.sides) sides.{&simple} But I'm getting a list of all of the imgsrc instead of a count of the number of sides.  Am I using the wrong command, or is this not working as intended? This post makes it seem like I should be getting a count. What I want would be this (I faked it using the 'currentside' attribute and setting the token to the final image):
1713543745
timmaugh
Pro
API Scripter
Hey, Jarren... I think that post is a little out of date. I've been meaning to consolidate all of the Fetch documentation to its wiki entry , but I have to wait for the wiki login information to clear up, at this point. The property you are looking for is "sidecount" (or "sidescount" -- that works, too). !/w gm @(selected|character_name) image has a total of @(selected.sidescount) sides.{&simple}
1713544355
timmaugh
Pro
API Scripter
The retrievable properties are currently spread out over these posts: Original 2.0 Launch Thread Text, Path, and Deck properties (from graphic-cards, ie, those that have been played to the VTT) Table, Page, Handout properties, as well as new-API update properties now available for Characters, Tokens, Campaign And, interestingly, in none of those is the "sidescount" property documented! *sigh* I have a bit of work to consolidate all of this and make sure it's complete once the wiki becomes available, again. =D
Awesome, thanks!  Next question: I realized that my current macro has a query that can be replaced by inserting the sidecount plus one, and I got the {&math} to evaluate within the macro.  Excellent!  But it appears the {&simple} tag adds a lot of whitespace to the output - is there a way to adjust that?  The partial command from my macro for comparison - this doesn't have the {&math} portion, but that's all working fine... it's just adding a lot of whitespace: !/w gm &{template:traits} {{name=?{Photo Name? (Name in 'Scenes' chat menu)} Photo}} {{source= ?{New Photo Width? (Get width from photo info)} x ?{New Photo Height? (Get height from photo info)}}} {{description=**Instructions** 1. Drop new image onto map layer 2. Click on Scenes image on Map layer and click the 'Add-Image' button then use new image as target 3. Open 'Change-Scene' macro and add code from this output}} {&simple} /w gm &{template:traits} {{name=?{Photo Name? (Name in 'Scenes' chat menu)} Photo}} {{source= ?{New Photo Width? (Get width from photo info)} x ?{New Photo Height? (Get height from photo info)}}} {{description=**Instructions** 1. Drop new image onto map layer 2. Click on Scenes image on Map layer and click the 'Add-Image' button then use new image as target 3. Open 'Change-Scene' macro and add code from this output}}
1713550778

Edited 1713550894
timmaugh
Pro
API Scripter
Interesting... so what's happening on the backend is that ZeroFrame detects the line break series, substitutes a placeholder in that spot, and then, when all the processing is done and it's ready to release the message, it does a quick replacement in the other direction to put the line breaks back in. It seems that native templates (from chat to output) process the line break into some other series of characters. But we can work around that. Stepping Stone Solution (Better Solution, Below) You could, if you were only worried about the white space of the line breaks, compact the command down to a single line while inserting %NEWLINE% where the line breaks should be. However, since this would put the line breaks back in before ZeroFrame saw the message, you'd be back to the same issue... so this would require one further obfuscation: !/w gm &{template:traits} {{name=?{Photo Name? (Name in 'Scenes' chat menu)} Photo}} {{source= ?{New Photo Width? (Get width from photo info)} x ?{New Photo Height? (Get height from photo info)}}} {{description=**Instructions**%^NEWLINE^%1. Drop new image onto map layer%^NEWLINE^%2. Click on Scenes image on Map layer and click the 'Add-Image' button then use new image as target%^NEWLINE^%3. Open 'Change-Scene' macro and add code from this output}} {&simple}{&escape ^} The {&escape} tag tells ZeroFrame that anywhere it sees the included string of characters (here, just the "^" character), it should remove them before releasing the message. That way we can use the ^ to hide the %NEWLINE% tag: %^NEWLINE^% But handling the white space of the final message is probably not your only concern. You very likely still would like to keep the same line breaks as are in the original command line because that aids with readability. For that, see the Better Solution. Better Solution You didn't have to go far. =D To preserve the line breaks in the original message, we're going to use Plugger's new replace() function. We'll have it look for the particular placeholder text ZeroFrame uses as a "line break indicator": ({&br}) ...and replace it with the escaped new line series discussed above: %^NEWLINE^% And we'll still use the same {&escape} tag to make those new line references be recognizable to Roll20 at the right time (when the message is released). The final solution would look like this: !/w gm &{template:traits} {{name=?{Photo Name? (Name in 'Scenes' chat menu)} Photo}} {{source= ?{New Photo Width? (Get width from photo info)} x ?{New Photo Height? (Get height from photo info)}}} {{description=**Instructions**{&eval}replace(--source|` 1. Drop new image onto map layer 2. Click on Scenes image on Map layer and click the 'Add-Image' button then use new image as target 3. Open 'Change-Scene' macro and add code from this output` --find|`({&br})`|%^NEWLINE^%){&/eval} }} {&simple}{&escape ^} Note that because the "source" text for the replace function will have a closing parentheses (because we know it will have ZeroFrame line-break placeholders), we need to enclose it in some quotation mark (I use the tick mark). The same goes for the "find" argument, since that is specifically referring to the line break placeholder. Also of note that this requires Plugger v1.08, which was just merged this week. If you got the one-click version of the Toolbox, you're golden.
That did it!  These Metascripts are really powerful, but also a bit tricky to parse through, so thank you for explaining! I learn a bit more each time. :) One day I'll be able to write a macro using them without any help at all! For anyone else who is interested in what I'm doing, here is my current process (requires a Roll20 Pro subscription):  I have a ' Scenes ' page with a rollable token linked to a 'Scenes' character right in the middle of the page on the Map layer.  I wanted the images to end up fitting within the same area so that the image wouldn't feel like it was having Enlarge/Reduce cast on it each time I swapped the image, so I needed a little math to calculate the image size for the TokenMod chat menu.  Then I put an invisible token of the same size on the Objects layer that is also linked to the 'Scenes' character. Finally I put an invisible ' PlayerStart ' token in the middle of the image to pull players there when the page is loaded. I have two Ability macros on the Scenes character for adding new images and adding to the chat menu: 1-Add-Image !token-mod --set imgsrc|+@{target|token_id} --ids -N1zF-xlLCzZfIWn47KB 2-Width-Calc !{&eval}replace(--source|`/w gm &{template:traits} {{name=?{Photo Name? (Name in 'Scenes' chat menu)} Photo}} {{source= ?{New Photo Width? (Get width from photo info)} x ?{New Photo Height? (Get height from photo info)}}} {{description=**Instructions** 1. Drop new image onto map layer 2. Click on Scenes image on Map layer and click the 'Add-Image' button then use new image as target 3. Open 'Change-Scene' macro and add code from this output **Wide (Landscape) Photo** [?{Photo Name? (Name in 'Scenes' chat menu)}](!token-mod --ignore-selected --set currentside|{&math @(selected.sidescount)} width|[[1400]] height|[[{&math [[round(?{New Photo Height? (Get height from photo info)} / [[?{New Photo Width? (Get width from photo info)} / 1400]])]]}]] --ids @{Scenes|character_id}) **Tall (Portrait) Photo** [?{Photo Name? (Name in 'Scenes' chat menu)}](!token-mod --ignore-selected --set currentside|{&math @(selected.sidescount)} width|[[{&math [[round(?{New Photo Width? (Get width from photo info)} / [[?{New Photo Height? (Get height from photo info)} / 1200]])]] }]] height|[[1200]] --ids @{Scenes|character_id}) }} ` --find|`({&br})`|%^NEWLINE^%){&/eval} }} {&simple}{&escape ^} I add the new photo to the Scenes token, then run the 'Width Calculation' macro, which will give me command buttons that I can paste into my 'Change-Scene' chat menu. Because 'Scary Forest' was wider than tall (landscape), I cut-and-pasted the first TokenMod command button and pasted it into my 'Change Scene' chat menu, which  looks like this: Change-Scene /w gm &{template:npcaction} {{rname=Scenes}} {{description=[Mere of Dead Men Spooky](!token-mod --ignore-selected --set currentside|1 --ids @{Scenes|character_id} !token-mod --ignore-selected width|[[1400]] height|[[1024]] --ids @{Scenes|character_id}) [Mere of Dead Men Bright](!token-mod --ignore-selected --set currentside|2 width|[[1400]] height|[[930]] --ids @{Scenes|character_id}) [Leilon](!token-mod --ignore-selected --set currentside|3 width|[[1400]] height|[[788]] --ids @{Scenes|character_id}) [Grassland](!token-mod --ignore-selected --set currentside|7 width|[[1400]] height|[[788]] --ids @{Scenes|character_id}) [Wayside Inn](!token-mod --ignore-selected --set currentside|10 width|[[1400]] height|[[800]] --ids @{Scenes|character_id}) [Scary Forest](!token-mod --ignore-selected --set currentside|19 width|[[1400]] height|[[420]] --ids @{Scenes|character_id}) [**Phandalin Scenes**](~Scenes|Phandalin-Scenes) [**Neverwinter Scenes**](~Scenes|Neverwinter-Scenes)}} The macro makes sure that images get set to a maximum width of 1400 and a maximum height of 1200, but otherwise retain their dimensions. 
1713568605
timmaugh
Pro
API Scripter
That sounds pretty cool! Can you share screenshots of the final effect? Also, I thought you mentioned you wanted the +1 in the {&math} tag... didn't you? Currently you have: --set currentside|{&math @(selected.sidescount)} Maybe I misunderstood...
1713804636

Edited 1713804742
timmaugh said: That sounds pretty cool! Can you share screenshots of the final effect? Also, I thought you mentioned you wanted the +1 in the {&math} tag... didn't you? Currently you have: --set currentside|{&math @(selected.sidescount)} Maybe I misunderstood... With my previous setup I had a separate macro just to get the new side number, which I ran before adding the photo (take the current number of images and add one, and that will be the number to use in the query for the TokenMod command). I adjusted it to add the new image first, then run a macro for the TokenMod output, so the new image is the last side and no longer needs to add one. Here's what my setup looks like: 1. Add new image to Map layer and select current Scenes token 2. Click on '1-Add-Image' macro to add the new image to the mutli-sided Scenes token 3. Click on '2-Width-Calc' macro to get the TokenMod command that will be added to the 'Change-Scenes' macro. Use the Width and Height of the image from right-clicking on the image on my computer.  4. Open the 'Change-Scenes' macro and put the new TokenMod command in the chat menu. 5. On the Objects layer, click on the transparent image and run the 'Change-Scenes' macro for the list of images that I've added and click on whichever scene I want to display. (Sorry about the small size on the gif... I had to shrink it down to get it under 10mb)