Noticed something and not sure if it's a bug, or just a quirk i need to capture. When entering a value for a token bar value (such as bar1_value) through the UI, it gets saved as a string. However, when set via code, it can be saved as a numeric value. This is causing problems with findObjs(). If the value is entered in the UI form, findObjs() needs to be set to search as a string ie. bar1_value: "0" . If I set the value in code to the number 0, I have to use findObjs with bar1_value: 0 . This means two different search techniques depending if the value was entered in code or through the UI. Now that I know this is occurring, I know I need to go in and do some cleanup with a on("graphic:change") event to convert any entry in these boxes to their numeric equivalent (at least the ones I plan to do findObjs() against), or I need to save my values in code as strings, which in turn means potentially having to convert back to numeric equivalents if I need to do any calculations. Guess in my thought process, a "bar1_value" field gives the impression that it stores a numeric value (as does "bar1_max" or "aura1_radius"). Seems that the conversion to numeric should occur at the UI form entry if the main purpose of this field is to be numeric. Would save further conversions and/or event captures. Or am I way off base? Is there a reason of which I'm not aware that the values for bars and auras are saved as strings when entered in the UI forms? Verification I had set up this bit of code to search for a specific token. I enter a value of 0 into the UI for bar1_value, then run my command !Test. It searches for that token by ID and by bar1_value where bar1_value is numeric. Then it changes the value of bar1_value in code to 0, and searches again using the same criteria. The first search returns no matches, and the second return the expected count of 1. Here's also the log output... i excluded irrelevant fields to save space. {"_id":"-JFT0t6PRjz2fFn14Sq7", ... ,"bar1_value":0, ... } {"_id":"-JFT0t6PRjz2fFn14Sq7", ... ,"bar1_value":"1", ... } {"_id":"-JFT0t6PRjz2fFn14Sq7", ... ,"bar1_value":"0", ... } "- found 0" // searched against a numeric 0 "- found 1" // searched against a numeric 0 after .set statement {"_id":"-JFT0t6PRjz2fFn14Sq7", ... ,"bar1_value":0, ... } And the test code... The the results are the same if I start with a numeric value of 0. The first findObjs() returns no objects, then .set to "0", and the second findObjs() returns the expected obj. on("chat:message", function (msg) { if (msg.type != "api" || msg.content != "!Test") return;
//set variables var thisID = "-JFT0t6PRjz2fFn14Sq7"; var thisObj = getObj("graphic", thisID); var found = [];
//search as is found = findObjs({ _type: "graphic", _id: thisID, bar1_value: 0, }); log("- found " + found.length);
//set test values to numeric thisObj.set({ bar1_value: 0, });
//search after numeric set found = findObjs({ _type: "graphic", _id: thisID, bar1_value: 0, }); log("- found " + found.length);
});