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] - Token Light setter

1404513787

Edited 1404513866
on('chat:message', function(msg) { if(msg.type != 'api') return; var selected = msg.selected; if(msg.content.indexOf("!day") === 0 || !selected) return; _.each(selected, function(obj) { if(obj._type != 'graphic') return; // only day graphics var tok = getObj('graphic', obj._id); if(tok.get('subtype') != 'token') return; // don't try to day cards var numb = 150; tok.set("light_radius", numb); tok.set("light_dimradius", numb); }); }); What am I missing? TypeError: Cannot call method 'set' of undefined at lights (evalmachine. :110:12) at evalmachine. :117:7 at eval ( I hate errors that mean nothing :( Give me VB!!!
1404534342
The Aaron
Roll20 Production Team
API Scripter
It's easier to read your code if you format it with the code style: on('chat:message', function(msg) { if(msg.type != 'api') return; var selected = msg.selected; if(msg.content.indexOf("!day") === 0 || !selected) return; _.each(selected, function(obj) { if(obj._type != 'graphic') return; // only day graphics var tok = getObj('graphic', obj._id); if(tok.get('subtype') != 'token') return; // don't try to day cards var numb = 150; tok.set("light_radius", numb); tok.set("light_dimradius", numb); }); }); I'm not sure what you did to get that error. The way you have this written, executing !day will cause it to return. You probably mean to have !== 0 or === -1 . on('chat:message', function(msg) { if(msg.type != 'api') { return; } var selected = msg.selected; if( msg.content.indexOf("!day") === -1 || !selected ) { return; } _.each( selected, function(obj) { if( obj._type != 'graphic' ) { return; // only day graphics } var tok = getObj( 'graphic', obj._id ); if( !tok || tok.get('subtype') != 'token' ) { return; // don't try to day cards } var numb = 150; tok.set("light_radius", numb); tok.set("light_dimradius", numb); }); }); It's a good idea to always use {} after if() s. Also, be sure to check the returned object is valid (the !tok I added above.) before using it. Your error message was generated because your tok instance had a value of undefined .
Thank you for your time once again Aaron, unfortunately even with your code : <a href="https://gist.github.com/anonymous/63562aaa484380a1" rel="nofollow">https://gist.github.com/anonymous/63562aaa484380a1</a>... I still get TypeError: Cannot call method 'set' of undefined at lights (evalmachine. :223:12) at evalmachine. :230:7 at eval (
1404593140
The Aaron
Roll20 Production Team
API Scripter
hmm.. if you want to PM me a link to your game and GM me (or did you do that already?) I'd be happy to jump in there and help you debug it. I'm not getting the error when I use it in my test campaign...
1404594011
The Aaron
Roll20 Production Team
API Scripter
Try this: on('chat:message', function(msg) { if(msg.type != 'api') { return; } var selected = msg.selected; if( msg.content.indexOf("!day") === -1 || !selected ) { return; } _.each( selected, function(obj) { if( obj._type != 'graphic' ) { return; // only day graphics } var tok = getObj( 'graphic', obj._id ); if( !tok || tok.get('subtype') != 'token' ) { return; // don't try to day cards } var numb = 150; try { tok.set("light_radius", numb); tok.set("light_dimradius", numb); } catch (e) { log('Error Setting Light on Tok. Tok was:'); log(tok); } }); }); and lets see what pops up in the log when it fails.