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

Issue in script getting the character object from selected token

I am porting some of my utility scripts from my Castle & Crusades game to a D&D 5E game and am seeing a strange issue.  The one I am working on is my mass initiative script.  It is working properly  on my C&C game but I am getting an error -  ReferenceError: getCharacterObj is not defined so I am a bit perplexed as to why this is happening.  Here is the top portion of the code, with the line of code failing marked with *** function rollSelectedInitiative(selectedToken) {     Campaign().set('initiativepage',false)          var tokenType = selectedToken._type     var tokenID = selectedToken._id     var tokenObj = getObj("graphic", tokenID)     var tokenPageID = tokenObj.get('pageid') ***    var characterObj = getCharacterObj(selectedToken)     var characterRace = getAttrByName(characterObj.id,'Race','current')     var characterHP = parseInt(tokenObj.get('bar1_value'),10)     var InitiativeMod = InitiativeMod = parseInt(getAttrByName(characterObj.id,'initiative_bonus','current'),10)     var turnOrder     var initRoll = randomInteger(20)*1
1588962657
The Aaron
Roll20 Production Team
API Scripter
getCharacterObj() is not a Roll20 function, it must be defined in another script you're using and is being leaked into the global namespace where this script is depending on it.
1588962814

Edited 1588962844
Thanks I will check for that.  Is there a code script I can replace that with that is part of the standard functions?
1588963368
The Aaron
Roll20 Production Team
API Scripter
var characterObj = getObj('character',(tokenObj||{get:()=>{}}).get('represents')); That should work in that line.  Since tokenObj isn't being validated after creation, the ||{get:()=>{}} part will avoid a crash if that isn't a token that was selected.
Awesome as usual, thanks for the help
1588964778
The Aaron
Roll20 Production Team
API Scripter
No problem! =D