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] Statistic check

I am trying to write a simple api to roll a d20 and add a called attribute. !SC Dex would roll a d20 and add the value from the 'Dex' attribute. No errors... but no response to commands either. What have I done wrong? // :S on("chat:message", function (msg) { if (msg.type == "api" && msg.content.indexOf("!SC ") === 0) { var statType = msg.content.split(" "); var selected = msg.selected; _.each(selected, function(obj) { var tok = getObj("graphic", obj._id); var chara = tok.get("represents"); var stat = findObjs(({ _type: "attribute", name: statType, _characterid: chara },{caseInsensitive: true})[0]); if (typeof stat == 'undefined') { sendChat(msg.chara,"/w gm I did it wrong"); }else{ sendChat(msg.chara,"I rolled a [[1d20" + stat + "]] for the check!"); } } )} });
1402353459

Edited 1402353539
Lithl
Pro
Sheet Author
API Scripter
First, statType is an array with two elements ("!SC" and "Dex"). This is your primary problem. Second, you've got some extra parentheses on your findObjs call that's screwing you up. It should be findObjs({ type: "attribute", name: statType, characterid: chara },{caseInsensitive: true})[0]; (assuming you edit the code so that statType is a string instead of an array) Third, stat will be an attribute object, not a number. You're also missing a "+" after the d20. You'll want ...[[1d20+"+stat.get("current")+"]]... Fourth, msg.chara isn't defined. Your options here are either msg.who or else "character|"+chara
1402355890

Edited 1402358205
Thanks! As you can tell. I'm new to this. I worked it out thanks to you! // global var on("chat:message", function (msg) { if (msg.type == "api" && msg.content.indexOf("!SC ") === 0) { var command = msg.content.split(" "); var statType = _.rest(msg.content.split(" ")).join(" ").toLowerCase(); var selected = msg.selected; _.each(selected, function(obj) { var tok = getObj("graphic", obj._id); var chara = tok.get("represents"); var stat = findObjs({ _type: "attribute", name: statType, _characterid: chara },{caseInsensitive: true})[0]; if (typeof stat == 'undefined') { sendChat(msg.who,"/w gm I did it wrong"); }else{ sendChat("character|"+chara,"I rolled a [[1d20+" + stat.get("current") + "]] for the "+statType+" check!"); } } )} });