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

[Sheet worker] Lowest of these two number

1495193008

Edited 1495193348
Coal Powered Puppet
Pro
Sheet Author
I am trying to get a sheet to pick the lowest of two numbers, one of which is inside a repeating field .  Is it possible? This works outside a repeating field: on("change:strength change:strength_rank change:maximum_dice_pool sheet:opened", function() {     getAttrs(['strength', 'maximum_dice_pool'], function(values) {         setAttrs({              strength_1: (Math.floor(Math.min.apply(null, Object.values(values))))          });     }); }); but I can't get this to work with something inside a repeating field: on("change:repeating_skillsanew:skill1_total change:maximum_dice_pool sheet:opened", function() {     getAttrs(['repeating_skillsanew_skill1_total', 'maximum_dice_pool'], function(values) {         setAttrs({              repeating_skillsanew_skill1_rating_1: (Math.floor(Math.min.apply(null, Object.values(values))))         });     }); }); Any ideas?
1495213391
Lithl
Pro
Sheet Author
API Scripter
What result are you getting? The first thing I would try would be Object.values(values).map(parseInt), since attribute values are often stored as a string.
I am getting some really weird results, honestly.  Since ' repeating_skillsanew_skill1_total ' is made up by adding two other numbers together, I think the sheet worker is keeping them as separate numbers, and then sorts them. How do I use  Object.values(values).map(parseInt) ?  I have no idea what any of the means
Is it possible to put these numbers into a matrix or index and then have the index reference the lowest number? Or the first number if they are organized by size?
...I don't know about matrices or indexes either.  Can you elaborate? The numbers are not static, and will change as the character develops.
I am referring to a form of list as it would be called in Lisp. Is there a way to generate these two numbers, put them in an organized list, index, or matrix (a group that can be referenced may be a better explanation) and then call on the lowest number within that group OR if its organized by how large the number is then reference the first number in that list
I got something to almost work: on("change:repeating_skillsanew:skill1_total change:maximum_dice_pool sheet:opened", function() {     getAttrs(['repeating_skillsanew_skill1_total', 'repeating_skillsanew_maximum_dice'], function(values) {         setAttrs({              repeating_skillsanew_skill1_rating_1: (Math.floor(Math.min.apply(null, Object.values(values))))         });     }); }); And just have the maximum dice update with an 'if else' funuction.  But I am still getting weird numbers back 
1495225804

Edited 1495225899
Lithl
Pro
Sheet Author
API Scripter
Coal Powered Puppet said: I am getting some really weird results, honestly.  Since ' repeating_skillsanew_skill1_total ' is made up by adding two other numbers together, I think the sheet worker is keeping them as separate numbers, and then sorts them. Is skill1_total an autocalc field? If so, then values.repeating_skillsanew_skill1_total will be something like "@{a} + @{b}", not a number. I wrote  sheetworker-autocalc to help with that sort of problem. (Although I admit I haven't tested it with repeating fields.) Coal Powered Puppet said: How do I use  Object.values(values).map(parseInt) ?  I have no idea what any of the means Object.values(values) (which you're already using) returns an array of the values in the object parameter. So an object like {a: 1, b: 2} would return [1, 2]. map is a function of the Array object, which takes a function ( parseInt in this case) and calls that function on each element in the array, returning an array of the results. ['1', '2'].map(parseInt) would result in [1, 2]. Putting it together, Object.values(values).map(parseInt) returns an array of all the values in values , after calling parseInt on each.
repeating_skillsanew_skill1_total is not an autocalc, but the result of a sheet worker script. I used this and got nowhere.  What am I doing wrong? on("change:repeating_skillsanew:skill1_select change:repeating_skillsanew:skill1_rating change:maximum_dice_pool sheet:opened", function() {     getAttrs(['repeating_skillsanew_skill1_total', 'repeating_skillsanew_skill1_max_dice'], function(values) {         setAttrs({              repeating_skillsanew_skill1_rating_1: (Math.floor(Math.min.apply(null, Object.values(values).map(parseInt))))          });     }); });
GOt it to work, in a clumsy, haphazard way.  Thanks for yawl's input