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

Spiritual Weapon API

So, I've been using this API with mixed success.&nbsp; You can find the link to the code here <a href="https://gist.github.com/palikhov/41ae06fded5b9780803665ec668fb35f" rel="nofollow">https://gist.github.com/palikhov/41ae06fded5b9780803665ec668fb35f</a> Nick Olivio did a video on it and I've followed his instructions, exactly.&nbsp; It works most of the time, but every so often, out of nowhere, I'll get an error in my game that turns off all scripts.&nbsp; I delete the Spiritual Weapon script, reload it and everything works again, until it pops up.&nbsp; I have absolutely zero idea what's going on.&nbsp; I hadn't changed anything.&nbsp; Also, when I was first using the script, it wouldn't work or it worked once, then immediately stopped working.&nbsp; Now it just fails, intermittently.&nbsp; What could be going on?&nbsp; It's very frustrating, as I'm not changing or adding anything.&nbsp; I've exhausted everything I can think of, but I'm very new to scripting.
Most of the guru's can pinpoint your issue if you paste the bit thats in red above the crashed sandbox,&nbsp;&nbsp;
1645647958
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
It could also be the intermittent catastrophic failure of the sandbox, and have nothing to do with the script. The API has been unstable and quirky for the better part of a year now.
&nbsp; For reference, the error message generated was: TypeError: Cannot read property 'get' of undefined TypeError: Cannot read property 'get' of undefined at apiscript.js:13661:40 at eval (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:168:1), &lt;anonymous&gt;:65:16) at Object.publish (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:168:1), &lt;anonymous&gt;:70:8) at /home/node/d20-api-server/api.js:1736:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546) at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489) at Zd.Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425) at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:111:400
1645661600

Edited 1645661835
Oosh
Sheet Author
API Scripter
It's probably crashing when you try to run the script on a token which is not linked to a character sheet. Here's a version with a bit of error checking thrown in: on("ready",function() { on("chat:message",function(msg){ if(msg.type=="api" &amp;&amp; msg.content.indexOf("!spiritualWeapon")==0 &amp;&amp; playerIsGM(msg.playerid)) { var selected = msg.selected; if (selected===undefined) { sendChat("API","Please select a character."); return; } var tok = getObj("graphic",selected[0]._id); if (!tok) return sendChat('spiritualWeapon', '/w gm Could not find token.'); var character = getObj("character",tok.get("represents")); var playerlist = character ? character.get("controlledby") : ''; createObj("graphic",{ left:tok.get("left")+70, top:tok.get("top"), height:70, width:70, pageid:tok.get("pageid"), layer:"objects", imgsrc:"<a href="https://s3.amazonaws.com/files.d20.io/images/104629087/ZzHGu7CiyzL0sZTuB8KfJA/thumb.png?15816820805" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/104629087/ZzHGu7CiyzL0sZTuB8KfJA/thumb.png?15816820805</a>", name:tok.get("name") + "'s Spiritual Weapon", controlledby:playerlist, aura1_radius:0, aura1_color:"#ffff00", showplayers_aura1:true }); sendChat(tok.get("name"),"I summoned a spiritual weapon."); spawnFx(tok.get("left")+70,tok.get("top"),"burst-holy",tok.get("pageid")); } }); }); This should leave a blank "controlledby" property for an unlinked token. If you have players controlling unlinked tokens, the script will need another line or two to find the direct controlledby property of the token if it fails to find a linked character. Edit - it may not be the SW script at all, like Keith said. But it's super short, and has a fairly obvious .get() trap in an anonymous function, so it fits the error message you posted.