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

sendChat with API message from API causes "cannot get from undefined"

1457029935

Edited 1457030669
This sendChat line causes an error log(character);/*prints the character */ log(character.get('name'));/*prints the name */ sendChat(character.get('name'),"!shadowrun BLUB"); Which is: TypeError: Cannot call method 'get' of undefined at handleInput (evalmachine.<anonymous>:7662:43) This line does not sendChat(character.get('name'),"!shadowrun BLUB",function(i) {}); and neither does this sendChat(character.get('name'),"BLUB"); handleInput is the callback for chat events and looks like this: var handleInput = function(msg) { var args; if (msg.type !== "api") { return; } log("CONTENT"); log(msg.content); args = msg.content.split(/\s+/); log("ARGS"); log(args); log(args[0]); log(msg); if(args[0] == "!shadowrun"){ log("Inside !shadowrun"); var character,character_id,action; if(args.indexOf("--character") !== -1){/*not entered*/} if(args.indexOf("--action") !== -1){/*not entered*/} if(character){/*not entered*/}else{log("no character");} }else{ } }; Anyone has ANY ideas how to debug what is undefined here? I already thought I have logged each and every object and none of those is undefined. I do not get the undefined get error when i send "!shadowrun BLUB" manually, which also enters this handleInput function.
You can't send api commands into chat via the api.
1457030691

Edited 1457030727
Good to know... But why?
Infinite loop prevention.
1457032172
The Aaron
Pro
API Scripter
(Which is still possible if you leave out the msg.type check!) Besides, if you want to call some other thing in the API, it's far more efficient not to make the round trip to the chat log.  Just expose it as a function on your module and call it directly.  All scripts are in the same global space: var ModuleA = ModuleA || (function(){ return { gotTest: function(){ sendChat('ModuleA', 'Someone got the test, apparently.'); }; }()); var ModuleB = ModuleB || (function(){ on('ready',function(){ on('chat:message',function(msg){ if(msg.type === 'api' && msg.content.match(/^!test/)){ ModuleA.gotTest(); } }); }); return { me: function(){ return 'ModuleB'; } }; }());