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 .
×

Issues with .get functionality

1447738609

Edited 1447803976
Hi guys, I've just implemented the patrol script from here:&nbsp; <a href="https://gist.github.com/anonymous/5980034" rel="nofollow">https://gist.github.com/anonymous/5980034</a> and using the object id obtained using this script:&nbsp; <a href="https://github.com/Roll20/roll20-api-scripts/blob/master/ObjectProperties/properties.js" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/blob/master/ObjectProperties/properties.js</a> I substituted lines 7-11 in the patrol script with the following code: on("ready", function() { //Wait until the ready event fires so we know the campaign is completely loaded. //Get a reference to our patrolling token. log("Going Guard A..."); var patroltoken = findObjs({_id: "-K3IXTEVdm4N5IFg9XhK"}); Although I'm getting the error: evalmachine.&lt;anonymous&gt;:431 if(patroltoken.get("status_greenmarker") === false) return; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^ TypeError: Object [object Object] has no method 'get' at null.&lt;anonymous&gt; (evalmachine.:431:23) at wrapper [as _onTimeout] (timers.js:261:14) at Timer.listOnTimeout [as ontimeout] (timers.js:112:15) I'm not exactly new to JavaScript but I am pretty new to this api. Is there a library I need to include with my .js files? I've never actually been able to get .get to work on any objects before. Thoughts? EDIT: To confirm that it was actually detecting said token, I added log(patroltoken); and it displayed the correct details. (Also could someone please tell me how to put the above code in appropriate tags (i.e. code/quote) like I'm seeing in other posts? I tried [code][/code] and [quote][/quote] but that didn't work. First time posting on these forums lol)
1447743892
Lithl
Pro
Sheet Author
API Scripter
findObjs returns an array of all objects which meet the properties passed to the function. While your code will always result in either 0 or 1 element in the array since ids are unique, it's still an array. If you know the id ahead of time, though, you should use getObj('graphic', id) instead of findObjs. You won't have the issue of the result being an array, and getObj will run faster. As for code formatting, click the Formatting button in the top-left corner of the Post Reply box and select "Code" to create a code box. These forums only use WYSIWYG, not any form of BBCode. The result is like this
Thanks so much Brian! I found the formatting button you were talking about, and no more errors :D