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 error not making sense OR something is working but shouldn't be?

1611987981

Edited 1611988301
Okay So I have a API function I use to update spell slots on my 5e CC Sheet It asks for 3 variables and looks like this // Syntax for this API is !UseASpellSlot <Selected|token_id> <Selected|character_id> <Level_of_spell_slot_used> on("ready",function() { on("chat:message",function(msg){ if(msg.type=="api" && msg.content.indexOf("!UseASpellSlot")==0 ){ var selected = msg.selected; if (selected===undefined){ sendChat("API","Please select a character."); return; } var args = msg.content.split(" "); var command = args.shift().substring(1); if (command == 'UseASpellSlot'){ if (args.length < 3) { sendChat('SYSTEM', 'You must provide a selected token id, character id and the spell slot level used'); return; } // 1st Parameter should be the Token's Id var Selected_Tok_Id = args[0]; var Selected_Char_Id = args[1]; var Selected_SpellSlotLevel = args[2]; var Selected_Token = getObj('graphic', Selected_Tok_Id); var Selected_Character = getObj('character',Selected_Char_Id); if (!Selected_Token) { sendChat('SYSTEM', 'Selected token id not provided.'); return; } if (!Selected_Character) { sendChat('SYSTEM', 'Selected character id not provided.'); return; } if (!Selected_SpellSlotLevel) { sendChat('SYSTEM', 'Selected spell slot levels not provided.'); return; } if (Selected_SpellSlotLevel < 1 || Selected_SpellSlotLevel > 9) { sendChat('SYSTEM', 'Selected Spell slot is either greater than 9 or less than 1, please provide the appropriate spell slot level.'); return; } //Preparing to get speakingas for sendChat var SpeakingAs = getObj('character', Selected_Token.get('represents')); if(!SpeakingAs){ SpeakingAs = Selected_Token.get('name'); } else { SpeakingAs = 'character|' + SpeakingAs.id; } var number = Selected_SpellSlotLevel; var SpellSlotName = "spell_slots_l"+number; var TestSpellSlot = findObjs ({ _type: "attribute", _characterid: Selected_Char_Id, name: SpellSlotName }); // This is where I plan on adding to spells used on the character sheet, below is just to make sure all values can be accessed properly first var CurrentSum = getAttrByName(Selected_Char_Id, "spell_slots_l"+number, "current"); var MaxSum = getAttrByName(Selected_Char_Id, "spell_slots_l"+number, "max"); //console.log(MaxSum); //sendChat(SpeakingAs,"MaxSum = " + MaxSum); CurrentSum = parseInt(CurrentSum,10); MaxSum = parseInt(MaxSum,10); //sendChat(SpeakingAs,"MaxSum = " + MaxSum); // Increment Spell Used CurrentSum = CurrentSum + 1; if (CurrentSum > MaxSum){ CurrentSum = MaxSum; sendChat(SpeakingAs,"It appears I tried used a Spell Slot that was not available to me!"); } else { if(!TestSpellSlot){ sendChat(SpeakingAs, "It appears the spell slot variable for the spell level I used is Undefined, please examine your characters attributes and try again"); return; } else{ TestSpellSlot[0].set("current",CurrentSum); } } /*sendChat(SpeakingAs,"CurrentSum = " + CurrentSum); sendChat(SpeakingAs,"MaxSum = " + MaxSum); sendChat(SpeakingAs,"TestSpellSlot[0].get(''current'') = " + TestSpellSlot[0].get("current")); sendChat(SpeakingAs,"TestSpellSlot[0].get(''max'') = " + TestSpellSlot[0].get("max")); */ } // If command == UseASpellSlot } // If statement from the UsaASpellSlot and Api is msg.type }); }); It works fine No problem no errors... I even did SendChat( of MaxSum *after Parse* and it gives me the correct number To gain perspective, this is the code for the spells slots... <div class="sheet-row sheet"> <div class="sheet-col-1-4 sheet-center sheet-small-label sheet-margin-top">1</div> <div class="sheet-col-1-4"> <input type="number" name="attr_spell_slots_l1" value="0" min="0" max="4" step="1" /> </div> <div class="sheet-col-1-4"> <input type="hidden" name="attr_helper_spell_slots_l1" value="(@{spell_slots_l1_max})" /> <input type="number" name="attr_spell_slots_l1_max" value="( ((ceil((@{multiclassspellcasterlevel})/1e10))*2) + (ceil((@{multiclassspellcasterlevel}-1)/1e10)) + (ceil((@{multiclassspellcasterlevel}-2)/1e10)) )" disabled="disabled" /> </div> <div class="sheet-col-1-4"> <input type="number" name="attr_spellpoints_cost1" value="2" disabled="disabled"/> </div> </div> <div class="sheet-row sheet"> <div class="sheet-col-1-4 sheet-center sheet-small-label sheet-margin-top">2</div> <div class="sheet-col-1-4"> <input type="number" name="attr_spell_slots_l2" value="0" min="0" max="3" step="1" /> </div> <div class="sheet-col-1-4"> <input type="hidden" name="attr_helper_spell_slots_l2" value="(@{spell_slots_l2_max})" /> <input type="number" name="attr_spell_slots_l2_max" value="( ((ceil((@{multiclassspellcasterlevel}-2)/1e10))*2) + (ceil((@{multiclassspellcasterlevel}-3)/1e10)) )" disabled="disabled" /> </div> <div class="sheet-col-1-4"> <input type="number" name="attr_spellpoints_cost2" value="3" disabled="disabled"/> </div> </div> <div class="sheet-row sheet"> <div class="sheet-col-1-4 sheet-center sheet-small-label sheet-margin-top">3</div> <div class="sheet-col-1-4"> <input type="number" name="attr_spell_slots_l3" value="0" min="0" max="3" step="1" /> </div> <div class="sheet-col-1-4"> <input type="hidden" name="attr_helper_spell_slots_l3" value="(@{spell_slots_l3_max})" /> <input type="number" name="attr_spell_slots_l3_max" value="( ((ceil((@{multiclassspellcasterlevel}-4)/1e10))*2) + (ceil((@{multiclassspellcasterlevel}-5)/1e10)) )" disabled="disabled" /> </div> <div class="sheet-col-1-4"> <input type="number" name="attr_spellpoints_cost3" value="5" disabled="disabled"/> </div> </div> <div class="sheet-row sheet"> <div class="sheet-col-1-4 sheet-center sheet-small-label sheet-margin-top">4</div> <div class="sheet-col-1-4"> <input type="number" name="attr_spell_slots_l4" value="0" min="0" max="3" step="1" /> </div> <div class="sheet-col-1-4"> <input type="hidden" name="attr_helper_spell_slots_l4" value="(@{spell_slots_l4_max})" /> <input type="number" name="attr_spell_slots_l4_max" value="( (ceil((@{multiclassspellcasterlevel}-6)/1e10)) + (ceil((@{multiclassspellcasterlevel}-7)/1e10)) + (ceil((@{multiclassspellcasterlevel}-8)/1e10)) )" disabled="disabled" /> </div> <div class="sheet-col-1-4"> <input type="number" name="attr_spellpoints_cost4" value="6" disabled="disabled"/> </div> </div> <div class="sheet-row sheet"> <div class="sheet-col-1-4 sheet-center sheet-small-label sheet-margin-top">5</div> <div class="sheet-col-1-4"> <input type="number" name="attr_spell_slots_l5" value="0" min="0" max="3" step="1" /> </div> <div class="sheet-col-1-4"> <input type="hidden" name="attr_helper_spell_slots_l5" value="(@{spell_slots_l5_max})" /> <input type="number" name="attr_spell_slots_l5_max" value="( (ceil((@{multiclassspellcasterlevel}-8)/1e10)) + (ceil((@{multiclassspellcasterlevel}-9)/1e10)) + (ceil((@{multiclassspellcasterlevel}-17)/1e10)) )" disabled="disabled" /> </div> <div class="sheet-col-1-4"> <input type="number" name="attr_spellpoints_cost5" value="7" disabled="disabled"/> </div> </div> <div class="sheet-row sheet"> <div class="sheet-col-1-4 sheet-center sheet-small-label sheet-margin-top">6</div> <div class="sheet-col-1-4"> <input type="number" name="attr_spell_slots_l6" value="0" min="0" max="2" step="1" /> </div> <div class="sheet-col-1-4"> <input type="hidden" name="attr_helper_spell_slots_l6" value="(@{spell_slots_l6_max})" /> <input type="number" name="attr_spell_slots_l6_max" value="( (ceil((@{multiclassspellcasterlevel}-10)/1e10)) + (ceil((@{multiclassspellcasterlevel}-18)/1e10)) )" disabled="disabled" /> </div> <div class="sheet-col-1-4"> <input type="number" name="attr_spellpoints_cost6" value="9" disabled="disabled"/> </div> </div> <div class="sheet-row sheet"> <div class="sheet-col-1-4 sheet-center sheet-small-label sheet-margin-top">7</div> <div class="sheet-col-1-4"> <input type="number" name="attr_spell_slots_l7" value="0" min="0" max="2" step="1" /> </div> <div class="sheet-col-1-4"> <input type="hidden" name="attr_helper_spell_slots_l7" value="(@{spell_slots_l7_max})" /> <input type="number" name="attr_spell_slots_l7_max" value="( (ceil((@{multiclassspellcasterlevel}-12)/1e10)) + (ceil((@{multiclassspellcasterlevel}-19)/1e10)) )"disabled="disabled" /> </div> <div class="sheet-col-1-4"> <input type="number" name="attr_spellpoints_cost7" value="10" disabled="disabled"/> </div> </div> <div class="sheet-row sheet"> <div class="sheet-col-1-4 sheet-center sheet-small-label sheet-margin-top">8</div> <div class="sheet-col-1-4"> <input type="number" name="attr_spell_slots_l8" value="0" min="0" max="1" step="1" /> </div> <div class="sheet-col-1-4"> <input type="hidden" name="attr_helper_spell_slots_l8" value="(@{spell_slots_l8_max})" /> <input type="number" name="attr_spell_slots_l8_max" value="( (ceil((@{multiclassspellcasterlevel}-14)/1e10)) )" disabled="disabled" /> </div> <div class="sheet-col-1-4"> <input type="number" name="attr_spellpoints_cost8" value="11" disabled="disabled"/> </div> </div> <div class="sheet-row sheet"> <div class="sheet-col-1-4 sheet-center sheet-small-label sheet-margin-top">9</div> <div class="sheet-col-1-4"> <input type="number" name="attr_spell_slots_l9" value="0" min="0" max="1" step="1" /> </div> <div class="sheet-col-1-4"> <input type="hidden" name="attr_helper_spell_slots_l9" value="(@{spell_slots_l9_max})" /> <input type="number" name="attr_spell_slots_l9_max" value="( (ceil((@{multiclassspellcasterlevel}-16)/1e10)) )" disabled="disabled" /> </div> <div class="sheet-col-1-4"> <input type="number" name="attr_spellpoints_cost9" value="13" disabled="disabled"/> </div> </div> <div class="sheet-row sheet"> <div class="sheet-row sheet-sub-header"> <div class="sheet-col-1 sheet-vert-bottom sheet-center sheet-small-label">Multiclass Spellcaster Level</div> </div> <div class="sheet-col-4-4"> <input type="number" name="attr_hiddenmulticlassspellcasterlevel" value="@{multiclassspellcasterlevel}" disabled="disabled" /> <input type="hidden" name="attr_multiclassspellcasterlevel" value="((ceil(@{arcane_trickster_level}/3)) + (ceil(@{eldritch_knight_level}/3)) + (ceil(@{paladin_level}/2)) + (ceil(@{artificer_level}/2)) + (ceil(@{ranger_level}/2)) + (@{wizard_level}) + (@{sorcerer_level}) + (@{druid_level}) + (@{cleric_level}) + (@{bard_level}) )" /> </div> </div> Notice Max is a bunch of Autocalc fields with lots of variables... those variables are not autocald fields, they are incrementally increased on (as attr_paladin_level, etc...)  So Now I am trying to make the same function for Warlock Slots, cause they are separate.  // Syntax for this API is !UseASpellSlot <Selected|token_id> <Selected|character_id> <Level_of_spell_slot_used> on("ready",function() { on("chat:message",function(msg){ if(msg.type=="api" && msg.content.indexOf("!UseAWarlockSpellSlot")==0 ){ var selected = msg.selected; if (selected===undefined){ sendChat("API","Please select a character."); return; } var args = msg.content.split(" "); var command = args.shift().substring(1); if (command == 'UseAWarlockSpellSlot'){ if (args.length < 2) { sendChat('SYSTEM', 'You must provide a selected token id and character id'); return; } // 1st Parameter should be the Token's Id var Selected_Tok_Id = args[0]; var Selected_Char_Id = args[1]; var Selected_Token = getObj('graphic', Selected_Tok_Id); var Selected_Character = getObj('character',Selected_Char_Id); if (!Selected_Token) { sendChat('SYSTEM', 'Selected token id not provided.'); return; } if (!Selected_Character) { sendChat('SYSTEM', 'Selected character id not provided.'); return; } //Preparing to get speakingas for sendChat var SpeakingAs = getObj('character', Selected_Token.get('represents')); if(!SpeakingAs){ SpeakingAs = Selected_Token.get('name'); } else { SpeakingAs = 'character|' + SpeakingAs.id; } var SpellSlotName = "warlock_spell_slots"; var TestSpellSlot = findObjs ({ _type: "attribute", _characterid: Selected_Char_Id, name: SpellSlotName }); var SpellSlotMaxName = "warlock_spell_slots_max"; var TestSpellSlotMax = findObjs ({ _type: "attribute", _characterid: Selected_Char_Id, name: SpellSlotMaxName }); // This is where I plan on adding to spells used on the character sheet, below is just to make sure all values can be accessed properly first var CurrentSum = getAttrByName(Selected_Char_Id, "warlock_spell_slots", "current"); var MaxSum = getAttrByName(Selected_Char_Id, "warlock_spell_slots", "max"); //console.log(MaxSum); sendChat(SpeakingAs,"MaxSum = " + MaxSum); CurrentSum = parseInt(CurrentSum,10); MaxSum = parseInt(MaxSum,10); sendChat(SpeakingAs,"MaxSum = " + MaxSum); // sendChat(SpeakingAs,"MaxSum = " + MaxSum); // Increment Spell Used CurrentSum = CurrentSum + 1; if (CurrentSum > MaxSum){ CurrentSum = MaxSum; sendChat(SpeakingAs,"It appears I tried used a Spell Slot that was not available to me!"); } else { if(!TestSpellSlot){ sendChat(SpeakingAs, "It appears the spell slot variable for the spell level I used is Undefined, please examine your characters attributes and try again"); return; } else{ TestSpellSlot[0].set("current",CurrentSum); } } /*sendChat(SpeakingAs,"CurrentSum = " + CurrentSum); sendChat(SpeakingAs,"MaxSum = " + MaxSum); sendChat(SpeakingAs,"TestSpellSlot[0].get(''current'') = " + TestSpellSlot[0].get("current")); sendChat(SpeakingAs,"TestSpellSlot[0].get(''max'') = " + TestSpellSlot[0].get("max")); */ } // If command == UseASpellSlot } // If statement from the UsaASpellSlot and Api is msg.type }); }); Several things, I removed the Spell level cause Warlock spell levels are all the same, all the matter if they have slots available (max)  When I try to run this it doesn't catch the max slots, because it thinks max is NAN after parse, cause Max still has the ceil().... garbage from the autocalc fields. However the first example also utilized autocalc and it worked fine.... Here is the code for how Warlock slots and max are handled... <div class="sheet-row"> <div class="sheet-col-1-4 sheet-margin-top">Spell Slots</div> <div class="sheet-col-1-4"> <input type="number" name="attr_warlock_spell_slots" value="0" min="0" step="1" /> </div> <div class="sheet-col-1-4"> <input type="number" name="attr_warlock_spell_slots_max" value="(( (ceil(@{warlock_level}/1e10)) + (ceil((@{warlock_level}-1)/1e10)) + (ceil((@{warlock_level}-10)/1e10)) + (ceil((@{warlock_level}-16)/1e10)) ))" disabled="disabled" /> </div> <div class="sheet-col-1-4"> <input type="number" name="attr_warlock_spell_slots_level" value="(( (ceil(@{warlock_level}/1e10)) + (ceil((@{warlock_level}-2)/1e10)) + (ceil((@{warlock_level}-4)/1e10)) + (ceil((@{warlock_level}-6)/1e10)) + (ceil((@{warlock_level}-8)/1e10)) ))" disabled="disabled" /> </div> </div> I also get an Error from the API warning me about this... "ERROR: Did not specify an attribute name when referencing attribute using @{warlock_level}" "Error at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:575:11) at String.replace (<anonymous>) at Object.d20.textchat.doChatInput (eval at <anonymous> (/home/node/d20-api-server/api.js:158:1), <anonymous>:549:29) at sendChat (/home/node/d20-api-server/api.js:1816:16) at apiscript.js:13440:17 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:1662: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)" As if my Warlock is not defined, when it clearly is  <div class="sheet-col-1-9 sheet-align-left sheet-padr"> <input type="number" name="attr_warlock_level" value="0" min="0" max="20" step="1"/> </div> I would just like to know what the heck am I doing so differently to get such a different result from both of these API's I will say it is indeed updating the spell slot (which could be done with setCharAttr really..) but it is not catching the max value and is allowing it to be pushed higher than max (do to Max being interpreted as garbage)
1611992371

Edited 1611992383
I think I got it to work? So on the Attributes and Abilities page, those variables were not showing up, so I have to toggle values and set some values (for example the Max space" manually and afterwards it works? Apparently I was never calling the Garbage for the first one I was calling what was on the Attribute page max value and it was a constant... not sure if it evaluated to that value or not but I guess I have an answer? still seems weird.