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

TypeError: Object -57 has no method 'indexOf'

1445971985

Edited 1445976252
WurmD
KS Backer
indexOf works. It has worked before. Now it says TypeError: Object -57 has no method 'indexOf' totals = _.reduce(findObjs({     pageid: page,     type: 'graphic',     isdrawing: false,     layer: 'objects' }),function(m,o){     log(o.get('_id'));     if(o.get('name').indexOf( 'Treasury' ) > -1) {          m.treasury+=parseFloat(o.get('bar3_value')) || 0;      } return m; },{ bar1: 0, bar2: 0, cityIncome: 0, numberOfcities: 0, treasury: 0, resourceIncome: 0}); // this is where you initialize fields but checking the _id of the object turns out: "-K08foEXiyy8ZuuVyORh" "-K08h-y2pZjxrTKeHGIW" "-K08i9nf6wr_lBhWNDDe" How do I find which one is object -57, to help with debugging?
1445976514
The Aaron
Pro
API Scripter
If I had to guess, I'd say some script has set the name of the token to the integer value -57, rather than a string '-57'.  The easiest way to guard against that is with implicit conversion to a string: totals = _.reduce(findObjs({     pageid: page,     type: 'graphic',     isdrawing: false,     layer: 'objects' }), function(m,o){     log(o.get('_id'));     if( (''+o.get('name')) .indexOf( 'Treasury' ) > -1) {          m.treasury+=parseFloat(o.get('bar3_value')) || 0;      } return m; }, { bar1: 0, bar2: 0, cityIncome: 0, numberOfcities: 0, treasury: 0, resourceIncome: 0 } ); // this is where you initialize fields
Indeed, that is exactly what happened, and that protection works :) wizard..