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

Refreshing an attribute with MAX at some point

If I want to refresh a attribute value with its MAX version at some point, what code can I use. I tried the 'set attribute macro' one but it doesn't seem to handle calls to existing attribute values.  A Bar value will do just as well.
command is not defined I took out the bar1 and bar2 values, was I supposed to do something else or place it somehow ?  I just added it as a new script called resetBar3.js. Thanks for that :)
Oh sorry. That was part of a script. Let me add the rest of it.

Edited 1454325267
Here's the full script with the part needed that defines what command is... I also included the !clear command that simply removes all status icons but doesn't change any bars. I used these to reset all the tokens on a map to their fully healed, default state in my D&D campaigns. Basically, I'd just hit CTR + A and use !reset to fix them all. on("chat:message", function(msg) {     // Exit if not an api command     if (msg.type != "api") return;          // Get the API Chat Command     msg.who = msg.who.replace(" (GM)", "");     msg.content = msg.content.replace("(GM) ", "");     var command = msg.content.split(" ", 1);     // Removes all status markers from selected tokens...     // Usage: !clear     if (command == "!clear") {         _.each(msg.selected, function(obj) {             var Token = getObj("graphic", obj._id);             var DefaultIcons = "";             if (Token.get("represents") !== "") {                 DefaultIcons = findObjs({_type: "attribute", name: "DefaultIcons", _characterid: Token.get("represents")})[0];                 DefaultIcons = (DefaultIcons !== undefined) ? DefaultIcons.get("current") : "";             }             Token.set("statusmarkers", DefaultIcons);         });     }     // Resets selected tokens to their fully healed state...     // Usage: !reset     if (command == "!reset") {         _.each(msg.selected, function(obj) {             // Get the Token and its max bar values...             var Token = getObj("graphic", obj._id);             var Bar1Max = Token.get("bar1_max");             var Bar2Max = Token.get("bar2_max");             var Bar3Max = Token.get("bar3_max");             var DefaultIcons = "";                          // If the Token represents a character, check to see if the Token             // has any default icons to set. Usage should be markername@value             // Example: grenade@2             if (Token.get("represents") !== "") {                 DefaultIcons = findObjs({_type: "attribute", name: "DefaultIcons", _characterid: Token.get("represents")})[0];                 DefaultIcons = (DefaultIcons !== undefined) ? DefaultIcons.get("current") : "";             }                          // Reset bar values and remove all status markers except those              // marked as default icons...             if (Bar1Max !== null) Token.set("bar1_value", Bar1Max);             if (Bar2Max !== null) Token.set("bar2_value", Bar2Max);             if (Bar3Max !== null) Token.set("bar3_value", Bar3Max);             Token.set("statusmarkers", DefaultIcons);         });     } });
That works great, many thanks :)