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

[Help] Cycling Images and sheet workers

My irong kingdoms sheet uses  Brian's cycling images that look like 0, 1, 2, and 3.  I would love to make two buttons/radio buttons/checkboxes to act as arrow keys, increasing or decreasing the number (in this case, changing to the next image.  Any ideas how to accomplish this? Right now, using sheet workers, I have the cycling images linked to a set of radio buttons, but I am displeased with it. 
1456910632
Finderski
Pro
Sheet Author
Compendium Curator
The only way I could think of would be to use a sheet worker. I'd probably use two check boxes. Then when the increase one is checked, the sheet worker would kick off, increment the number field and then uncheck the box (essentially resetting it). The same with the other box, only decrementing...
1456912351
Lithl
Pro
Sheet Author
API Scripter
Yup, I would do the same thing as GV. A checkbox on each side of your cycling button, a sheetworker that reacts to the value of either checkbox changing, and then increments or decrements the radio button value as desired.
1456920413

Edited 1456921376
Coal Powered Puppet
Pro
Sheet Author
Awesome!   I got that work this morning (after coffee) after failing to get it to work last night. Now, where do I look to see an example on how to set a maximum and minimum value for the cycling image? Meaning, if I have only four images (numbered 0 to 3), how do I keep the sheetworker from exceeding the maximum value? Edit: The internet is littered with a varity of examples of how to do this in javascript, but I'm having a rough time figuring out how to apply them.  Here is my code for the increasing checkbox: on("change:feat_up ", function() {     getAttrs(["feat_up", "feat"], function(values) {         setAttrs({             feat: (+values.feat + 1)                      });     }); });
1456923462
Finderski
Pro
Sheet Author
Compendium Curator
Coal Powered Puppet said: Awesome!   I got that work this morning (after coffee) after failing to get it to work last night. Now, where do I look to see an example on how to set a maximum and minimum value for the cycling image? Meaning, if I have only four images (numbered 0 to 3), how do I keep the sheetworker from exceeding the maximum value? Edit: The internet is littered with a varity of examples of how to do this in javascript, but I'm having a rough time figuring out how to apply them.  Here is my code for the increasing checkbox: on("change:feat_up ", function() {     getAttrs(["feat_up", "feat"], function(values) {         setAttrs({             feat: (+values.feat + 1)                      });     }); }); You could use an if/else statement and if the feat value < 0, then feat = 0, else if feat > 3 then feat = 3. Here's an example of how to use the if/else type statement: on("sheet:opened change:xp change:rank", function() { getAttrs(["xp", "rank"], function(value) { console.log("xp value: " + value.xp); console.log("rank value: " + value.rank); if (value.xp >=80) { console.log("Setting rank to Legendary"); setAttrs({Rank: 5}); } else if (value.xp >=60) { console.log("Setting rank to Heroic"); setAttrs({Rank: 4}); } else if (value.xp >=40) { console.log("Setting rank to Veteran"); setAttrs({Rank: 3}); } else if (value.xp >=20) { console.log("Setting rank to Seasoned"); setAttrs({Rank: 2}); } else { console.log("Setting rank to Novice"); setAttrs({Rank: 1}); } }); }); You could do the value check before or after setting the attribute once, though I'd probably recommend doing the check before setting the attribute, so you only need to set it once.
You can also use Math.min() and Math.max(). So if you always want it to be from 0 - 3 (inclusive of each): Math.max(Math.min(parseInt(values.feat, 10) + 1, 3), 0); That means it will be the lower value between the feat and 3, and the higher value between the feat and 0. So, 0-3.
Because its not working, I am to assume the code is not suppose to look like this? on("change:feat_up ", function() {     getAttrs(["feat_up", "feat"], function(values) {         setAttrs({             Math.max(Math.min(parseInt(values.feat, 10) + 1, 3), 0);         });     }); }); I did the "If maximum" bit to work, but hte minimum part is still laughing at me.  
1456954482

Edited 1456954515
Riley D.
Roll20 Team
So I think it would be&nbsp; setAttrs({ &nbsp; &nbsp; feat:&nbsp;Math.max(Math.min(parseInt(values.feat, 10) + 1, 3), 0) }); (You have to tell setAttrs what attribute you are setting). If that doesn't work still then feel free to post a gist ( <a href="http://gist.github.com" rel="nofollow">http://gist.github.com</a> ) of your full code so we can take a look.
1456954940

Edited 1456955004
Coal Powered Puppet
Pro
Sheet Author
This works! on("change:feat_up", function() { &nbsp; &nbsp; getAttrs(["feat_up", "feat"], function(values) { &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; feat: Math.max(Math.min(parseInt(values.feat, 10) + 1, 3), 0) &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; }); }); on("change:feat_down", function() { &nbsp; &nbsp; getAttrs(["feat_down", "feat"], function(values) { &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; feat: Math.max(Math.min(parseInt(values.feat, 10) - 1, 3), 0) &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; }); }); ThisworksthisworksthisworksthisworksthisworksthisworksthisworksthisworksthisworksthisworksthisworksthiswoooooooooOOOoooooorks! Thank you Riley! I mean, ahem. &nbsp;Yes, this appears to be functioning within acceptible parameters. &nbsp;You have my gratitude.
1456955149

Edited 1456955160
Riley D.
Roll20 Team
Coal Powered Puppet said: Thank you Riley! I mean, ahem. &nbsp;Yes, this appears to be functioning within acceptible parameters. &nbsp;You have my gratitude. Glad to be of service :-)