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