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 Locate Token via characterid to change status markers

1589210703

Edited 1589210866
Giger
Pro
API Scripter
Hi Everyone - i'm using a very old script now, called Bloodied and Dead status markers.  It's simple and a very reliable script. I'm trying to catch when someone uses !longrest from the OGL companion script, so that the status markers can update correctly.  But after hours of trying to I just can't figure it out. I'm getting the characterID from the msg the player sends to initiate the long rest.  That was relatively easy - but im stuck on finding that persons token on the page, and then updating the status marker.  I have a feeling its something simple, but im stumpled.  Any guidance would be amazing.  TIA //problematic code     on("chat:message", function(msg, obj) { if (msg.type !== "api") return; if (msg.content.split(" ")[0] == "!longrest") { var CharName = msg.playerid; sendChat("Mr. Sleep","/gm "+CharName+"used longrest!") ; tokens = findObjs({type: 'graphic', represents: CharName});             //tokens.set isn't a function - but not sure how to takes "tokens" and then set the status marker tokens.set({ status_redmarker: false }); } }); Full code, for reference: // originally created by Ken Bauer log('-=> Blood Tracker Online <=-'); //Detect if !longrest has been used on("chat:message", function(msg, obj) { if (msg.type !== "api") return; if (msg.content.split(" ")[0] == "!longrest") { var CharName = msg.playerid; sendChat("Mr. Sleep","/gm "+CharName+"used longrest!") ; tokens = findObjs({type: 'graphic', represents: CharName}); tokens.set({ status_redmarker: false }); } }); //main script on("change:graphic", function(obj) { if(obj.get("bar1_max") === "") return; if(obj.get("bar1_value") <= obj.get("bar1_max") / 2) { obj.set({ status_redmarker: true }); }else{ obj.set({ status_redmarker: false }); } if(obj.get("bar1_value") <= 0 && obj.get("bar1_value") > -10) { obj.set({ status_dead: true }); // var who=obj.get('name'); // sendChat('The Reaper',''+who+' is passed out! ') } else if(obj.get("bar1_value") <= -10) { obj.set({ status_dead: true }); //var who=obj.get('name'); // sendChat('The Reaper',''+who+' is dead! ') } else { obj.set({ status_dead: false }); } });
1589212799
The Aaron
Roll20 Production Team
API Scripter
You're super close with this.  You need to call set on the individual tokens, but you're trying to call it on the array.  You need to iterate over the array and call it on each contained token: //problematic code     on("chat:message", function(msg, obj) { if (msg.type !== "api") return; if (msg.content.split(" ")[0] == "!longrest") { var CharName = msg.playerid; sendChat("Mr. Sleep","/gm "+CharName+"used longrest!") ; tokens = findObjs({type: 'graphic', represents: CharName});             //tokens.set isn't a function - but not sure how to takes "tokens" and then set the status marker tokens .forEach( t=> t .set({ status_redmarker: false }) ) ; } });
1589214006
Giger
Pro
API Scripter
Aaron, you're always so helpful - i appreciate you. While that code didn't seem to do the trick (no errors, but tokens didn't update), I've been playing with the code below, and that seemed to do the trick....much more messy than I'd prefer though. Next up, is to figure out how to stop my initiative turn order announcer from dying, if i delete the token before clearing the turn orders. Thanks again, Aaron. _.each(msg.selected, function(objInfo) { var obj = getObj(objInfo._type, objInfo._id); if( obj.get("_type") == "graphic" ){ if( obj.get("_subtype") == "token" ){ obj.set({ status_redmarker: false }); obj.set({ status_dead: false }); } } });
1589215436
The Aaron
Roll20 Production Team
API Scripter
No problem!  Glad you found a solution.  Without seeing the code, you probably just need to add a check that the token you get from getObj() is valid, something like if(token) { /* stuff */ }