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

Asking for help already...

First tiny script I'm trying to get running and I'm clearly missing something. All this should do is look for a message with !lantern, give the lanternholder variable the name/id of the token selected when the message is sent, and then (mostly to get feedback on if it worked) send a message. I feel pretty sheepish about posting this issue, but here we go. Thanks in advance for any help. <a href="https://gist.github.com/Keign/6c4084f87c4e6a430e86" rel="nofollow">https://gist.github.com/Keign/6c4084f87c4e6a430e86</a>...
1425697715

Edited 1425699287
Hey, don't sweat it. Learning a new language always has its stumbling blocks :) I think this was your intention? on("chat:message", function(msg) { if(msg.type == "api" && msg.content.indexOf("!lantern") !== -1) { var lanternholder_name = null; var lanternholder_charName = null; var token = null; var charId = null; var character = null; if (msg.selected && msg.selected.length &gt; 0) { // nab the first in the list of selected objects token = msg.selected[0]; // ensure it's a token graphic, and not a drawing or something else token = getObj('graphic',token._id); if (token && token.get('_subtype') == 'token') { // we have a token, now we want the name? lanternholder_name = token.get('name'); // or do we want the journal entry binded to the token.. the name of that? charId = token.get('represents'); if (charId) character = getObj('character',charId); // we found an attached character sheet, and a name too! if (character) lanternholder_charName = character.get('name'); else { // boohoo log('welp, no character journal attached to this little token!'); } } } // we'll put an or statement here if one of of these is non-null, it'll // chose that, else, it'll do the first. If there is neither, some random // word sendChat("Update", (lanternholder_charName||lanternholder_name||"placeholder!") + " has been selected to bear the Lantern."); } }); You were missing a closure at the end on ( ... function() { } ) ; The Wiki has a wealth of information to mine. The API isn't completely documented, but the various object parts are: <a href="https://wiki.roll20.net/API:Chat" rel="nofollow">https://wiki.roll20.net/API:Chat</a> That should tell you all the properties in message which are: who playerid content origRoll inlinerolls target target_name selected Inlinerolls is the most annoying, but after some trial and error and copious use of the 'log(...)' function, and it'll come to you. Javascript is a very lax language to figure out, even if you have no programming background. EDIT: I mis-interpreted what you wanted. See the example script for an easy to read solution.
1425749419

Edited 1425749611
It would appear the closure was exactly what I needed. I swear I checked for that issue a dozen times. But now it does something, so huzzah! I'll add in some of the basic filtering stuff like you have (checking if it is a token, making sure something is selected) just to keep it from acting funny. - Thank you. It's been too long since I've done even the lightest programming