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 .
×
May your rolls be merry + bright! 🎄
Create a free account

Help with modifying Bloodied Script

I want to use my own custom status marker for the bloodied. I tryed few different things and nothing seems to work. The name of the status is 'blood'.  'status_blood: true' didnt work nor did  'status_bloodmarker: true'. I'm sure I'm just missing something small, but dont know what. THE CODE: var barValue = "bar1"; var acceptedValues = ["bar1", "bar2", "bar3"]; on('chat:message', function (msg) {       if (msg.type == 'api' && msg.content.indexOf('!ChangeBar') !== -1) {         var message = msg.content.split(" ")[1];         log("Message: " + message);         if (acceptedValues.includes(message)) {             barValue = message;             log("Blood and Dead bar value changed to " + message);         }     } }); on("change:graphic:bar1_value", function(obj) {     if(obj.get("bar1_max") === "") return;         if(obj.get("bar1_value") <= obj.get("bar1_max") / 2) {         obj.set({               status_blood: true         });     }     else{         obj.set({             status_blood: false         })     }     if(obj.get("bar1_value") <= 0) {       obj.set({          status_dead: true       });     }     else {       obj.set({         status_dead: false       });     } });
1711182648
Andrew R.
Pro
Sheet Author
I suggest you use  libTokenMarkers like TokenMod does.  libTokenMarkers provides an easy encapsulation around Custom Token Markers. It is a library for other scripts to use and does not have a user interface. It is intended to be a dependency for other scripts.
1711378638

Edited 1711566693
timmaugh
Forum Champion
API Scripter
I agree with Andrew that you should use libTokenMarkers. That can give you a handle on what markers are available in your campaign and help with understanding what markers are on a given token. Also, that's not how you set a status marker. Tokens don't have a property for each potential marker. They have a single statusmarkers property which is a comma-separated list of the markers currently assigned and their values. The marker names that appear in the statusmarkers list might contain double colons and then numbers after the name (this is how user-uploaded markers are differentiated; the number will be the same from game to game if you use the same marker set), and/or it might contain an "@" symbol followed by a number (this is how the value of the status is set). You'll need to account for this in trying to determine whether a token has a status marker assigned... because it is possible that you can assign the same marker to the token multiple times (through scripts you can do this). You will want to parse the string in the statusmarkers property to determine if the marker is already in there, then add it if necessary (by setting the "statusmarkers" property). Here is how my Fetch script gets the statuses from a token by using libTokenMarkers. Feed the statusmarkers property from a token into this to get the return of markers assigned:     const decomposeStatuses = (list = '') => {         return list.split(/\s*,\s*/g).filter(s => s.length)             .reduce((m, s) => {                 let origst = libTokenMarkers.getStatus(s.slice(0, /(@\d+$|:)/.test(s) ? /(@\d+$|:)/.exec(s).index : s.length));                 let st = _.clone(origst);                 if (!st) return m;                 st.num = /^.+@0*(\d+)/.test(s) ? /^.+@0*(\d+)/.exec(s)[1] : '';                 st.html = origst.getHTML();                 st.url = st.url || '';                 m.push(st);                 return m;             }, []);     }; Also, I would highly, highly suggest using these 2 scripts as a way to get to the bottom of these sort of issues (and to understand what properties are available on a given object: ScriptInfo  - can help disambiguate line numbers in errors Inspector  - can help you quickly understand the available data attached to an object (and flow from one object to another, related object). For instance, here is an inspection of a token, showing the statusmarkers property: