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] Test for a token bar value?

var Bar1Max = parseInt(obj.get("bar1_max")); If the token doesn't have any value set in bar 1 max, it will error out in the API that the object doesn't have a get method. TypeError: Object [object Object] has no method 'get' at evalmachine.<anonymous>:184:40 at Array.forEach (native) at Function._.each._.forEach (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:78:11) at Sandbox.<anonymous> (evalmachine.<anonymous>:180:11) at eval ( So how do I test to see if it exists without using get?
My guess is that you'd have to directly check it's bar1_max property through the graphic object: if(obj.bar1_max != ""){ var Bar1Max= parseInt(obj.get("bar1_max")); //other code } that'd be my best guess if you have the graphic object already there (assuming the graphic object is set up without any intermediate layers you'd have to parse through).
Dur, totally did not think of using .bar1_max.
Hrm, actually... I feel really dumb. I had forgotten to change obj to token. >_<
I always prefer to traverse through objects if I can, just for this reason. Though .get() is much better for conveying your intentions. also don't worry about it we all forget things.