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

Novice script editing

1447640197

Edited 1447803805
Hello all! I will start this by saying I'm very new to scripting, but I'm trying. I'm using  Eric D's script as it's one I can understand (again, new to this). I'm altering this script to add more than the 2 conditions listed. I'm able to get the new condition markers to appear at the values I want them to appear:  .6 = yellow, .4 = brown, and .2 = red. I think that's a nice gradient to show health decline. Now I'm running into 2 issues. Issue 1: For whatever reason, the yellow status icon will not work. I have subbed it in for purple, green, and blue with success. According to  this , it's still called yellow. I'm not sure what the deal with that is. It's a minor problem I can overlook, but I'm still curious as to what's the problem. Issue 2: Still being new to this, I'm not sure what "phrasing" I should use to get each status marker to be replaced by the successive marker. As it stands now when the HP value is reached, the yellow icon (if yellow worked) remains on the token, and brown is added next to it. Same for when the red value is reached. The prior icons remain on the token and red icon is just added next to them. What I have running now: var CONFIG = [ {barId: 1, barRatio: .6, status: "yellowmarker", whenLow: true}, {barId: 1, barRatio: .4, status: "brownmarker", whenLow: true}, {barId: 1, barRatio: .2, status: "redmarker", whenLow: true}, {barId: 1, barRatio: 0, status: "dead", whenLow: true}]; on("change:token", function(obj) { CONFIG.forEach(function(opts) { var maxValue = parseInt(obj.get("bar" + opts.barId + "_max")); var curValue = parseInt(obj.get("bar" + opts.barId + "_value")); //log(opts.barId + ": " + curValue + "/" + maxValue); if (maxValue != NaN && curValue != NaN) { var markerName = "status_" + opts.status; if (curValue <= (maxValue * opts.barRatio)) { obj.set(markerName, opts.whenLow); } else { obj.set(markerName, !opts.whenLow); } } }); }); I'm sure issue 2 is not hard to make happen, I'm just not knowledgeable enough at this time to work it out for myself. Issue 1 is still a mystery though. Any help would be appreciated!  
1447641567
Lithl
Pro
Sheet Author
API Scripter
If you precede each config line with an identical one using whenLow: false , you should get the replacement behavior you're looking for. For, for example: { barId: 1, barRatio: .6, status: 'yellow', whenLow: false }, { barId: 1, barRatio: .6, status: 'yellow', whenLow: true }, { barId: 1, barRatio: .4, status: 'brown', whenLow: false }, { barId: 1, barRatio: .4, status: 'brown', whenLow: true }, ... etc. If that doesn't work, I apologize. I've been awake for about 27 hours at the moment. =)
Brian said: If you precede each config line with an identical one using whenLow: false , you should get the replacement behavior you're looking for. For, for example: { barId: 1, barRatio: .6, status: 'yellow', whenLow: false }, { barId: 1, barRatio: .6, status: 'yellow', whenLow: true }, { barId: 1, barRatio: .4, status: 'brown', whenLow: false }, { barId: 1, barRatio: .4, status: 'brown', whenLow: true }, ... etc. If that doesn't work, I apologize. I've been awake for about 27 hours at the moment. =) Unfortunately, that did not work. It caused all the icons to be on the token when it was at full health (yellow still doesn't work, so I did it with purple in its place.) When the HP value reached ".4" it removed purple from the token. It removed brown when HP value was ".2" as well.  I very much appreciate your overworked brains effort though!
Shameless bump. I've tooled around with this some more, and I'm getting no closer to the desired effect. I'm looking past yellow not working, and just focusing on getting the status icons to be replaced when the new HP value is reached.  If there is another script that anyone knows about that will achieve the same affect, with minor alterations, I'm more than willing to try. 
The first issue appears to be a problem with setting the yellow marker like this: obj.set("status_yellowmarker", true). Reading the docs you linked it seems that should work, but it apparently it doesn't. The docs do mention that there is a new way to set the color markers using "status_yellow" which does work. The second issue has to do with how the script is written. It enables any statuses which are less than the current ratio for that bar. To fix this I tweaked it so that the options use a range instead. This is a little more flexible too, since you can have statuses overlap or have them be exclusive. I also added an option for value to the config. This lets you turn on a marker with a number overlay if you want to. Here's my tweaked version of the script: (function() {   var CONFIG = [       {barId: 1, minRatio: .4, maxRatio: .6, status: "yellow", val: true },       {barId: 1, minRatio: .2, maxRatio: .4, status: "brown", val: true },       {barId: 1, minRatio: 0, maxRatio: .2, status: "red", val: true },       {barId: 1, minRatio: Number.NEGATIVE_INFINITY, maxRatio: 0, status: "dead", val: true }];   var bars = _.groupBy(CONFIG, "barId");      on("change:token", function(obj) {     var max, cur, ratio, val;     _.each(bars, function(opts, key) {       cur =  parseInt(obj.get("bar" + key + "_value"));       max =  parseInt(obj.get("bar" + key + "_max"));       if (isNaN(cur) || isNaN(max)) return;       ratio = cur / max;       opts.forEach(function(opt) {         val = ratio <= opt.maxRatio && ratio > opt.minRatio ? opt.val : false;         obj.set("status_" + opt.status, val);       });     });   }); })();
Oh my goodness, thank you so much!  I was tooling around with the original and wasn't having too much success, but was willing to live with i because the original base script worked. But this - this is great. It works just how I wanted it to, you really don't know how much I appreciate it. 
Not a problem. Glad its working for you!