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 sandbox error message...

The following error is displayed in the API sandbox... Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again.  More info... For reference, the error message generated was:  TypeError: Cannot read property '1' of undefined TypeError: Cannot read property '1' of undefined at Object.addToTracker (apiscript.js:4283:30) at apiscript.js:4085:19 at Function._.each._.forEach (/home/node/d20-api-server/node_modules/underscore/underscore.js:186:9) at Object.handleTrackerMessage (apiscript.js:4068:7) at handleChatMessage (apiscript.js:4416:23) at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1634: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) This error appears to be related to the HeroTracker.js script I am running, but I have no idea what it means... Can anyone translate this into laymans terms?
1559221556
The Aaron
Roll20 Production Team
API Scripter
Some script you are using (likely something dealing with the turn order) is using a variable it expects to be object or array, but which is "undefined".  "Undefined" is javascript's empty special value. Likely it is deciding the turn order and expecting something in it, of fetching objects that don't actually exist. What scripts do you have installed? What were you doing when it happened?  I can't fully diagnose from my phone or I'd track down likely scripts by searching for the function "handleTrackerMessage".   
1559222608
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Initiative Tracker or HeroTracker , according to github.
1559223878
The Aaron
Roll20 Production Team
API Scripter
Ah, thanks Keith!  It's HeroTracker. Not sure what the cause is, I'd have to dig deeper tonight. 
The Aaron said: Ah, thanks Keith!  It's HeroTracker. Not sure what the cause is, I'd have to dig deeper tonight.  That would be really appreciated Sir...I have no idea why this has suddenly happened out of the blue. I had opened the initiative tracker and tried to add a token to it and nothing happened. This was all via macros that I have used many times in the past with no problems. So when I looked at the sandbox there was the error message. I have changed nothing. Cheers  Ray  :)
1559303606
The Aaron
Roll20 Production Team
API Scripter
It looks like the speed value supplied was incorrect, not a number from 0 to 12.  It could be coming from the --speed parameter, or from the SPD attribute.  Can you post the command you were using when it crashed?
1559433836

Edited 1559433873
Ray
Pro
Ahhh...that makes sense. I have redesigned my custom character sheet and changed the Attribute names from Capitals to Lower Case... Thanks Aaron...I will look at that as the most likely cause  :)
The Aaron said: It looks like the speed value supplied was incorrect, not a number from 0 to 12.  It could be coming from the --speed parameter, or from the SPD attribute.  Can you post the command you were using when it crashed? Ok Aaron...I figured out what the problem was... I redesigned the custom character sheet so that all Attributes which were in Capitals changed to lowercase, including "SPD" and "DEX" which were changed to "spd" and "dex" respectively. Then the problem occurred because the HeroTracker script was looking for the Capitalised names...straightforward so far. So...I changed the HeroTracker script to look for the "spd" and "dex" Attributes in the only line of code where they appeared within the script, then I saved the script and tried again...but the same error message occurred...damn! So...I changed the HeroTracker script back to capitals "SPD" and "DEX", and then changed my HTML in the custom sheet back to "SPD" and "DEX" and tried the Initiative macro, but the error still occurred....Double Damn!!!  I also spun up the sandbox just to make sure everything was good to go... So....to summarize...the HeroTracker script and the HTML both have the same Attribute names..."SPD" and "DEX", but the error still exists. My problem now is, I know that both the HTML and the HeroTracker script have the same Attribute names defined. My question now is how do I look at what the HeroTracker script is doing in order to figure out where the problem lies? Regards Ray
1559462719

Edited 1559462731
GiGs
Pro
Sheet Author
API Scripter
If you revert to the original form of the herotracker script (dont try to undo your edits, just reinstall the original from github), then you have two choices:  set DEX and SPD attribute names in your sheet to all caps. This should  work,  Herotracker lets you define different attribute names for dex and spd - no need to edit the code. Use --speed_field and --dex_field followed by the attribute name. If either of these isnt working, the problem is something to do with your dex and spd values, not the script, and not the attribute names. What does the html for them look like?
1559479035

Edited 1559479146
The Aaron
Roll20 Production Team
API Scripter
There's another possibility. Attributes are a bit loosely built. There are some places where they are case sensitive and some where they are not. It's possible your characters have multiple attributes with the same name because of the various case changes. With the cases matching in both HTML and API, try creating a new character and see if it works. You might try a fresh campaign, for that matter.  The API functions like findObjs() don't allow you to specify an ordering and return objects in their intrinsic order, which seems to always be creation order. That means old attributes are found before new ones. The common practice of finding something by name with findObj(...)[0] means you always find the old one. You could use findObj(...).pop(), but that might simply mask the issue.  Debugging a script largely consists of putting log(...) statements in problem areas and working your way through the path of the data until you find the problem. In the case of crashes, functional decomposition can help you narrow things down by giving you a descriptive callstack. 
1559480749
GiGs
Pro
Sheet Author
API Scripter
Good point! I've fallen foul of multiple attributes with the same name before, and should have remembered it. Wouldnt it be possible to use filterObjs to find duplicate named attributes?
1559481192
The Aaron
Roll20 Production Team
API Scripter
Definitely, though it would be more efficient to use findObjs and then filter (or reduce) the array (a few years ago, Riley added indexing that speeds up findObjs() quite a bit by pre-filtering down to a subset on type and some other qualities): let non_dup_attr = findObjs({ type: 'attribute', name: 'DEX', characterid: somechar.id }, {caseInsensitive: true}) .reduce((memo, attr, index, array)=>{ /* do some complicated analysis... */ return attr; },{});
GiGs said: If you revert to the original form of the herotracker script (dont try to undo your edits, just reinstall the original from github), then you have two choices:  set DEX and SPD attribute names in your sheet to all caps. This should  work,  Herotracker lets you define different attribute names for dex and spd - no need to edit the code. Use --speed_field and --dex_field followed by the attribute name. If either of these isnt working, the problem is something to do with your dex and spd values, not the script, and not the attribute names. What does the html for them look like? Ok...I deleted the HeroTracker.js script and reinstalled it from the source that I have saved as a Notepad file. Then I restarted the sandbox, as well as everything else I could think of, created a new character, and the problem persists...
The Aaron said: There's another possibility. Attributes are a bit loosely built. There are some places where they are case sensitive and some where they are not. It's possible your characters have multiple attributes with the same name because of the various case changes. With the cases matching in both HTML and API, try creating a new character and see if it works. You might try a fresh campaign, for that matter.  The API functions like findObjs() don't allow you to specify an ordering and return objects in their intrinsic order, which seems to always be creation order. That means old attributes are found before new ones. The common practice of finding something by name with findObj(...)[0] means you always find the old one. You could use findObj(...).pop(), but that might simply mask the issue.  Debugging a script largely consists of putting log(...) statements in problem areas and working your way through the path of the data until you find the problem. In the case of crashes, functional decomposition can help you narrow things down by giving you a descriptive callstack.  Ok Aaron...I created a completely new campaign, installed the HeroTracker.js script from my original Notepad backup copy, copied the HTML and CSS code from my custom character sheet, then I created a new character and the problem persists in the new campaign... I have no idea what to do now. I have gone through the HTML using a "find" command to make sure the DEX and SPD attributes are not duplicated anywhere else, and I am 100% certain they are not. I have also used a "find" command to search the HeroTracker.js script to make sure everything is in order. I am now at a total loss  :(
1559790789
The Aaron
Roll20 Production Team
API Scripter
Hmm.  If you want to PM me an invite to your game and GM me, I can try and track it down this weekend.. probably...
1559830677
GiGs
Pro
Sheet Author
API Scripter
Can you post the html from your character sheet where dex and speed are defined?
GiGs said: Can you post the html from your character sheet where dex and speed are defined?         <!-- DEFINE DEXTERITY -->         <div>             <div class="field40 right">DEX</div>             <div class="field10"></div>             <div class="field45 center">10</div>             <div class="field45 center">x3</div>             <input class="input30 center" type="number" name="attr_dexxp" value="0">             <div class="field45 center">20</div>             <div class="field10"></div>             <input class="input40 center" type="number" name="attr_DEX" disabled="true" value="(round(@{dexxp}/3)+10)">         </div>         <!-- DEFINE SPEED --> <div>             <div class="field40 right">SPD</div>             <div class="field10"></div>             <div class="field85b center">1+(DEX/10)</div>     <div class="field45 center">x10</div>     <input class="input30 center" type="number" name="attr_spdxp" value="0">     <div class="field45 center">4</div>             <div class="field10"></div>     <input class="input40 center" type="number" name="attr_SPD" disabled="true" value="floor(@{DEX}/10+(@{spdxp}/10))+1">         </div>
1560037636

Edited 1560037677
Ray
Pro
The Aaron said: Hmm.  If you want to PM me an invite to your game and GM me, I can try and track it down this weekend.. probably... Done....Thanks for your offer of help  :) Will add you to GM as soon as you accept...
1560038411
GiGs
Pro
Sheet Author
API Scripter
I wonder if its because the attributes are autocalc fields. I honestly dont know if this would affect it, but try - just temporarily - changing those  to simple attributes like  <input class="input40 center" type="number" name="attr_DEX" value="10"> and see if it works. I'd probably do that anyway, and have the cost not the stat be a calculated field.
1560038513
GiGs
Pro
Sheet Author
API Scripter
Also, turning the attributes into inline rolls is another thing to test, by changing the outer brackets to inline roll brackets:  <input class="input40 center" type="number" name="attr_DEX" disabled="true" value="[[round(@{dexxp}/3)+10]]"> I'd test both of these ideas.