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] Need some modification on a tiny script

So, I'm helping my GM setting up technical things from macros to recently scripts. I got a little script that update a marker on a token like this : on("change:graphic", function(obj) { if(obj.get("bar1_max") === "") return; if(obj.get("bar1_value") <= 4 ) { obj.set({ status_overdrive: true }); } else{ obj.set({ status_overdrive: false }) } if(obj.get("bar1_value") <= 0) { obj.set({ status_screaming: true }); } else { obj.set({ status_screaming: false }); } }); My problem is that in line 3 i want it not to be "<=4" but to be " <= 7 minus the value of an attribute of the character it's representing". I have not touched JS for a while and can't wrap my head over how to do it (not that I haven't tried seriously). Please send help !
1494845763
The Aaron
Pro
API Scripter
Here ya go, change out ' someattribute ' to the name of what attribute you're looking for: on("change:graphic", function(obj) {     let adjust = 0; /* variable for the adjustment */     /* find the attribute, if it exists */     let attr = findObjs({         characterid: obj.get('represents'), /* Character the object represents, could be empty */         name: ' someattribute '  /* name of the attribute to get */     })[0];  /* findObjs() returns an array, so take the first entry */     /* if we found it, get it's value or 0 */     if(attr){         /* attribute values are generally strings so convert to an integer, */         /* or use 0 if it can't be converted to an integer */         adjust = parseInt(attr.get('current'),10)||0;       }     if(obj.get("bar1_max") === "") return;     if(obj.get("bar1_value") <= (7-adjust) ) {         obj.set({             status_overdrive: true         });     }     else{         obj.set({             status_overdrive: false         });     }     if(obj.get("bar1_value") <= 0) {         obj.set({             status_screaming: true         });     }     else {         obj.set({             status_screaming: false         });     } });
Perfect I just tested it and works fine. Thank you !
1494852860
The Aaron
Pro
API Scripter
No problem!  Happy Rolling!