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

API Summon Script Error

1614132666

Edited 1614132817
Hello, I am very new to API and I'm trying to learn as I go.  I found a script that lets my cleric summon a spiritual weapon token.  However, I keep getting an error when the script attempts to give token control to the player.  I am sorry if this has been posted before but I was unable to find an answer.  Thank you for your time. Here is the coding: on("ready",function() {     on("chat:message",function(msg){         if(msg.type=="api" && msg.content.indexOf("!spiritualWeapon")==0 && playerIsGM(msg.playerid))         {             var selected = msg.selected;             if (selected===undefined)             {                 sendChat("API","Please select a character.");                 return;             }             var tok = getObj("graphic",selected[0]._id);             var character = getObj("character",tok.get("represents"));              var playerlist = character.get("controlledby");  (IF I DISABLE THIS PART OF THE SCRIPT IT WORKS BUT THE SUMMONED TOKEN HAS NO CONTROLER)                 createObj("graphic",{                 left:tok.get("left")+70,                 top:tok.get("top"),                 height:70,                 width:70,                 pageid:tok.get("pageid"),                 layer:"objects",                 imgsrc:" This is where I have a link for the summoned token Image ",                 name:tok.get("name") + "'s Spiritual Weapon",                 controlledby:playerlist , (IF I DISABLE THIS PART OF THE SCRIPT IT WORKS BUT THE SUMMONED TOKEN HAS NO CONTROLER)                 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 is the error message I receive: For reference, the error message generated was:  TypeError: Cannot read property 'get' of undefined TypeError: Cannot read property 'get' of undefined at apiscript.js:10371:40 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:154:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:154:1), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1663: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
1614133801
timmaugh
Pro
API Scripter
That error tells me no character was found at that line... and the character that was being looked for is the character represented by the token. Are you sure there is a value for the represented character on that token?
Hello, Thank you for your reply.  I took a screenshot of the character sheet and the token settings.  I have controlled by values, is there another place I need to look? This is the summoned Token settings, and as you can see the Controlled by field is blank. Thanks again.
1614138699
timmaugh
Pro
API Scripter
Your character has a "Controlled By" property set... but your token isn't getting you there. Look at the token's "Represents Character" field... it says "None/Generic Character". You want to make sure the token represents that character so that you can pass through the token to get to the character (exactly what your script is trying to do). =D
I believe I found my issue.  The token settings were set to "None/Generic Token".  Once I set that to the correct character POOF it's now working.  Thank you for kick starting my brain.
1614172560
David M.
Pro
API Scripter
FYI Skelator, you may want to check out my SpawnDefaultToken  script, as it can handle all kinds of tokens rather than hardcoding one per script. The one-click version is behind due to reasons, so I'd manually install if you wanted the latest functionality. Of course, if you are more interested in the educational side (learning js in the Roll20 environment), there are much less complex and much more cleanly written ones than Spawn to use as examples ;) 
1614173540
timmaugh
Pro
API Scripter
Och! Was going to mention your script, David! Chalk it up to the lateness of the hour, and the waggi-ness of a newly adopted tail! But, yes... Skelator, there are more universal, robust, and/or feature dense scripts that do the things you're looking to do. And while David may demur, he's done really cool things in Spawn. And even if he sees room for improvement (don't we all, in our own scripts?), there's something to be said for an involved and responsive dev like David in case you run into an issue or want some new gidget rolled into a script you love!
Thank you both for the help.   I'll give the script a try David, thank you.
Thank you for the script!  I have it set to summon the party onto a token I set on the map.  Now I have to get cracking on getting most of artwork uploaded into my personal library as I was using the freebies and the campaign tokens. Thanks Again!
1614207327

Edited 1614207338
David M.
Pro
API Scripter
Great! Hopefully you saw my comments in the thread regarding party summoning and using the new KeepLink command with v0.12 and later :)
I did thank you.  The script is doing exactly what I needed it to do.