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

Why the Red Zero?

Hi there, I have a script full of entries like this:     // SHIELD_EQUIPPED     if (shield_equipped && parseInt(shield_equipped, 10) !== 0)      {         tokens.forEach(function(token) {             token.set('status_Icon_-_Shield_Banner_1-1_marker_icon_token::255217');         }, this);     } else {         tokens.forEach(function(token) {             token.set('status_Icon_-_Shield_Banner_1-1_marker_icon_token::255217', false);         }, this);     } When the shield marker appears on a token there is a red zero on top of it. I do not like the zero. The zero does not like me. I cannot figure out how to rid myself of the zero. I fear the zero will win. Thank you for your help in defeating the zero.
1595661625
GiGs
Pro
Sheet Author
API Scripter
It might be something to do with using the old method of applying status markers, bust using the new status markers. This page has examples of using the new token markers:&nbsp; <a href="https://wiki.roll20.net/API:Token_Markers" rel="nofollow">https://wiki.roll20.net/API:Token_Markers</a> You might want to change that code to something like: tokens.forEach(function(token)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;let&nbsp;currentMarkers&nbsp;=&nbsp;token.get("statusmarkers").split(','); &nbsp;&nbsp;&nbsp;&nbsp;let&nbsp;shieldmarker&nbsp;=&nbsp;'status_Icon_-_Shield_Banner_1-1_marker_icon_token::255217'; &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(shield_equipped&nbsp;&amp;&amp;&nbsp;parseInt(shield_equipped)&nbsp;!==&nbsp;0)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!currentMarkers.includes(shieldmarker))&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentMarkers.push(shieldmarker); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;token.set("statusmarkers",&nbsp;currentMarkers.join(',')); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(currentMarkers.includes(shieldmarker))&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentMarkers.splice(currentMarkers.indexOf(shieldmarker),&nbsp;1); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;token.set("statusmarkers",&nbsp;currentMarkers.join(',')); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;} },&nbsp;this); I might combine some of those if statements and write it differently, but dont know what the rest of your script is doing so made the least intrusive change I could.
1595708421

Edited 1595709037
Hey, GiGs, Thanks for your response. That did the trick alright. But now I can't figure out how to make all the other triggers work together. For example, if I use only the shield portion I can get the shield to turn on and off. If, however, I add something else: // SHIELD_EQUIPPED tokens.forEach(function(token) { let currentMarkers = token.get("statusmarkers").split(','); let shieldmarker = 'status_Icon_-_Shield_Banner_1-1_marker_icon_token::255217'; if (shield_equipped &amp;&amp; parseInt(shield_equipped) !== 0) { if(!currentMarkers.includes(shieldmarker)) { currentMarkers.push(shieldmarker); token.set("statusmarkers", currentMarkers.join(',')); } } else { if (shield_equipped &amp;&amp; parseInt(shield_equipped) == 0) { currentMarkers.splice(currentMarkers.indexOf(shieldmarker), 1); token.set("statusmarkers", currentMarkers.join(',')); } } }, this); // MOUNTED tokens.forEach(function(token) { let currentMarkers = token.get("statusmarkers").split(','); let mountmarker = 'Icon_-_Mount_1-1_vehicle_icon_token::286697'; if (mounted &amp;&amp; parseInt(mounted) !== 0) { if(!currentMarkers.includes(mountmarker)) { currentMarkers.push(mountmarker); token.set("statusmarkers", currentMarkers.join(',')); } } else { if (mounted &amp;&amp; parseInt(mounted) == 0) { currentMarkers.splice(currentMarkers.indexOf(mountmarker), 1); token.set("statusmarkers", currentMarkers.join(',')); } } }, this); The mounted marker turns on and off as expected, but the shield marker misbehaves. It doesn't turn on and off when toggled, and in fact toggling the "mounted" option adds a new shield. So by mounting, dismounting, and mounting again there are three shield markers.
1595710906
GiGs
Pro
Sheet Author
API Scripter
Your else statement is incorrect. It should be: if (shield_equipped &amp;&amp; parseInt(shield_equipped) !== 0) { if(!currentMarkers.includes(shieldmarker)) { currentMarkers.push(shieldmarker); token.set("statusmarkers", currentMarkers.join(',')); } } else { &nbsp;if(currentMarkers.includes(shieldmarker))&nbsp;{ currentMarkers.splice(currentMarkers.indexOf(shieldmarker), 1); token.set("statusmarkers", currentMarkers.join(',')); } } But that wouldnt cause the problem. You have some faulty logic. I cant see how the rest of your script is set up, but the issue - I'm 99% sure - is the way you are checking two values: shield_equipped, and parseInt(shield_equipped). One should suffice. How are you getting the shield_equipped value?
1595711843

Edited 1595712249
GiGs
Pro
Sheet Author
API Scripter
Here's how I would approach your problem. First create a function to handle the changing of the markers. Since you are repeating the same code several times (well, at least twice), it is efficient to move that off into a function. Put this near the start of your script: //&nbsp;function&nbsp;to&nbsp;update&nbsp;status&nbsp;markers const&nbsp;changeMarkers&nbsp;=&nbsp;(currentMarkers,&nbsp;marker,&nbsp;test)&nbsp;=&gt;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;if(test&nbsp;&amp;&amp;&nbsp;!currentMarkers.includes(marker))&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentMarkers.push(marker); &nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;if&nbsp;(!test&nbsp;&amp;&amp;&nbsp;currentMarkers.includes(marker))&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currentMarkers.splice(currentMarkers.indexOf(marker),&nbsp;1); &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;currentMarkers; }; Then in your script, you need to evaluate your mounted and shield_equipped to true or false. (or 1 and 0, or similar). You then replace your code above with the following: tokens.forEach(function(token)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;let&nbsp;currentMarkers&nbsp;=&nbsp;token.get("statusmarkers").split(','); &nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;shieldMarker&nbsp;=&nbsp;'status_Icon_-_Shield_Banner_1-1_marker_icon_token::255217'; &nbsp;&nbsp;&nbsp;&nbsp;currentMarkers&nbsp;=&nbsp;changeMarkers(currentMarkers,&nbsp;shieldMarker,&nbsp;shield_equipped); &nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;mountMarker&nbsp;=&nbsp;'Icon_-_Mount_1-1_vehicle_icon_token::286697'; &nbsp;&nbsp;&nbsp;&nbsp;currentMarkers&nbsp;=&nbsp;changeMarkers(currentMarkers,&nbsp;mountMarker,&nbsp;mounted); &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;token.set("statusmarkers",&nbsp;currentMarkers.join(',')); },&nbsp;this); So you get the currentMarkers just once. You then send the currentMarkers, the shieldMarker name, and your shield_equipped value to the function above. It checks if you should add the shield marker or remove it. Then you move on to the mounted one, and the same thing happens. Each of these functions update the currentMarkers array, if needed. No change to the token is made until all checks have been made. Finally you update the token directly. But for this to work, you need a single value for the shield_equipped and mounted variables. They should be set up properly before you reach this point. So please reply to the question at the end of my post if you need help setting them up. By the way, is there any reason for the this &nbsp;at the end of your forEach loop? It looks to me like you can just drop it and change that line to } );