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 .
×

Rage Api script error

Hi all, i am trying to get this api script to work, but i am receiving this error that i dont know how to fix, can anyone help me please? var CHOSEN_STATUS = "strong"; var STRATTR = "Str-Mod"; var CONATTR = "Con-Mod"; var HPATTR = "HP"; var ACATTR = "AC"; var LEVATTR = "Level"; on("chat:message", function(msg) { if (msg.type == "api" && msg.content.indexOf("!Rage") !== -1) { _.each(msg.selected, function(objInfo) { var obj = getObj(objInfo._type, objInfo._id); if( obj.get("_type") == "graphic" ){ if( obj.get("_subtype") == "token" ){ var charID = obj.get("represents"); var StrAttr = findObjs({ name: STRATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ConAttr = findObjs({ name: CONATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var HPAttr = findObjs({ name: HPATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ACAttr = findObjs({ name: ACATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var LevAttr = findObjs({ name: LEVATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; if( obj.get("status_"+CHOSEN_STATUS) ){ sendChat("Rage-API", obj.get("name")+" toggling off."); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); obj.set("status_"+CHOSEN_STATUS, false); StrAttr.set("current", parseInt(StrAttr.get("current"))-4); ConAttr.set("current", parseInt(ConAttr.get("current"))-4); HPAttr.set("current", parseInt(HPAttr.get("current"))-(2*parseInt(LevAttr.get("current")))); ACAttr.set("current", parseInt(ACAttr.get("current"))+2); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); } else { sendChat("Rage-API", obj.get("name")+" toggling on."); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); obj.set("status_"+CHOSEN_STATUS, true); StrAttr.set("current", parseInt(StrAttr.get("current"))+4); ConAttr.set("current", parseInt(ConAttr.get("current"))+4); HPAttr.set("current", parseInt(HPAttr.get("current"))+(2*parseInt(LevAttr.get("current")))); ACAttr.set("current", parseInt(ACAttr.get("current"))-2); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); } } } }); } }); And this is the error i am getting. TypeError: Cannot read property 'set' of undefined TypeError: Cannot read property 'set' of undefined at apiscript.js:49:32 at Function.each (/home/node/d20-api-server/node_modules/underscore/underscore.js:1310:9) at apiscript.js:13:11 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) 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)
1609771507

Edited 1609774030
Jordan C.
Pro
API Scripter
Seems to be that it is not defining the HPAttr when it is supposed to here:                     var HPAttr = findObjs({ name: HPATTR, _type: "attribute", _characterid: charID } So, the problem is likely at the name since the charID is probably valid; That means the string 'HP' doesn't match an attribute for that character. My instinct is that 'HP' should be lower case but it depends entirely on your character sheet. E: missed the case insensitive piece
Hi Jordan, i've changed the script to match my character sheet but i am still getting an error var CHOSEN_STATUS = "strong"; var STRATTR = "str-temp"; var CONATTR = "con-temp"; var HPATTR = "hitpoints"; var ACATTR = "armorclass"; var LEVATTR = "level"; on("chat:message", function(msg) { if (msg.type == "api" && msg.content.indexOf("!Rage") !== -1) { _.each(msg.selected, function(objInfo) { var obj = getObj(objInfo._type, objInfo._id); if( obj.get("_type") == "graphic" ){ if( obj.get("_subtype") == "token" ){ var charID = obj.get("represents"); var StrAttr = findObjs({ name: STRATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ConAttr = findObjs({ name: CONATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var HPAttr = findObjs({ name: HPATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ACAttr = findObjs({ name: ACATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var LevAttr = findObjs({ name: LEVATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; if( obj.get("status_"+CHOSEN_STATUS) ){ sendChat("Rage-API", obj.get("name")+" toggling off."); obj.set("status_"+CHOSEN_STATUS, false); StrAttr.set("current", parseInt(StrAttr.get("current"))-4); ConAttr.set("current", parseInt(ConAttr.get("current"))-4); HPAttr.set("current", parseInt(HPAttr.get("current"))-(2*parseInt(LevAttr.get("current")))); ACAttr.set("current", parseInt(ACAttr.get("current"))+2); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); } else { sendChat("Rage-API", obj.get("name")+" toggling on."); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); obj.set("status_"+CHOSEN_STATUS, true); StrAttr.set("current", parseInt(StrAttr.get("current"))+4); ConAttr.set("current", parseInt(ConAttr.get("current"))+4); HPAttr.set("current", parseInt(HPAttr.get("current"))+(2*parseInt(LevAttr.get("current")))); ACAttr.set("current", parseInt(ACAttr.get("current"))-2); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); } } } }); } }); TypeError: Cannot read property 'set' of undefined TypeError: Cannot read property 'set' of undefined at apiscript.js:549:33 at Function.each (/home/node/d20-api-server/node_modules/underscore/underscore.js:1310:9) at apiscript.js:506:11 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) 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)
1609774522

Edited 1609775371
Jordan C.
Pro
API Scripter
It still must be returning undefined for one of the variables. can you screenshot the character sheet attribute page and highlight the ones you are looking to pull?  Also, can you run this version, it will tell you exactly which attribute is coming back undefined var CHOSEN_STATUS = "strong"; var STRATTR = "str-temp"; var CONATTR = "con-temp"; var HPATTR = "hitpoints"; var ACATTR = "armorclass"; var LEVATTR = "level"; on("chat:message", function(msg) { if (msg.type == "api" && msg.content.indexOf("!Rage") !== -1) { _.each(msg.selected, function(objInfo) { var obj = getObj(objInfo._type, objInfo._id); if( obj.get("_type") == "graphic" ){ if( obj.get("_subtype") == "token" ){ var charID = obj.get("represents"); var StrAttr = findObjs({ name: STRATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ConAttr = findObjs({ name: CONATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var HPAttr = findObjs({ name: HPATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ACAttr = findObjs({ name: ACATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var LevAttr = findObjs({ name: LEVATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; const CheckUndefined = (v, str) => { if (v === undefined) log(str + ' is undefined'); }; if( obj.get("status_"+CHOSEN_STATUS) ){ sendChat("Rage-API", obj.get("name")+" toggling off."); obj.set("status_"+CHOSEN_STATUS, false); CheckUndefined(StrAttr, 'Strength'); CheckUndefined(ConAttr, 'Constitution'); CheckUndefined(HPAttr, 'HP'); CheckUndefined(ACAttr, 'AC'); StrAttr.set("current", parseInt(StrAttr.get("current"))-4); ConAttr.set("current", parseInt(ConAttr.get("current"))-4); HPAttr.set("current", parseInt(HPAttr.get("current"))-(2*parseInt(LevAttr.get("current")))); ACAttr.set("current", parseInt(ACAttr.get("current"))+2); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); } else { sendChat("Rage-API", obj.get("name")+" toggling on."); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); CheckUndefined(StrAttr, 'Strength'); CheckUndefined(ConAttr, 'Constitution'); CheckUndefined(HPAttr, 'HP'); CheckUndefined(ACAttr, 'AC'); obj.set("status_"+CHOSEN_STATUS, true); StrAttr.set("current", parseInt(StrAttr.get("current"))+4); ConAttr.set("current", parseInt(ConAttr.get("current"))+4); HPAttr.set("current", parseInt(HPAttr.get("current"))+(2*parseInt(LevAttr.get("current")))); ACAttr.set("current", parseInt(ACAttr.get("current"))-2); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); } } } }); } });
This is what i am getting with your script SyntaxError: Unexpected token 'var'
This is the character sheet i am using, it is a translated version of Diana 3.5 character sheet  
1609775315

Edited 1609775385
Jordan C.
Pro
API Scripter
Sorry, I am stupid; replace this: const CheckUndefined = (var, str) => { if (var === undefined) log(str + ' is undefined'); }; With this: const CheckUndefined = (v, str) => { if (v === undefined) log(str + ' is undefined'); }; (Also edited the original)
TypeError: Cannot read property 'set' of undefined TypeError: Cannot read property 'set' of undefined at apiscript.js:560:33 at Function.each (/home/node/d20-api-server/node_modules/underscore/underscore.js:1310:9) at apiscript.js:506:11 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) 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)
1609775694
Jordan C.
Pro
API Scripter
Did the console log anything?
This TypeError: Cannot read property 'set' of undefined TypeError: Cannot read property 'set' of undefined     at apiscript.js:560:33     at Function.each (/home/node/d20-api-server/node_modules/underscore/underscore.js:1310:9)     at apiscript.js:506:11     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)     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)
1609776080
Jordan C.
Pro
API Scripter
This is the console log I am referring to:
yes sorry my bad, i haven't copied everything "Strength is undefined" "Constitution is undefined" "AC is undefined"
1609776459
Jordan C.
Pro
API Scripter
Okay, can you go into your character sheet and go to the panel below and make sure each of those names match and have a value?
Ok i think i managed to get somewhere. This is how i modified the script var CHOSEN_STATUS = "strong"; var STRATTR = "str"; var CONATTR = "con"; var HPATTR = "hitpoints"; var ACATTR = "miscac3bonus"; var LEVATTR = "level"; on("chat:message", function(msg) { if (msg.type == "api" && msg.content.indexOf("!Rage") !== -1) { _.each(msg.selected, function(objInfo) { var obj = getObj(objInfo._type, objInfo._id); if( obj.get("_type") == "graphic" ){ if( obj.get("_subtype") == "token" ){ var charID = obj.get("represents"); var StrAttr = findObjs({ name: STRATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ConAttr = findObjs({ name: CONATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var HPAttr = findObjs({ name: HPATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ACAttr = findObjs({ name: ACATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var LevAttr = findObjs({ name: LEVATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; const CheckUndefined = (v, str) => { if (v === undefined) log(str + ' is undefined'); }; if( obj.get("status_"+CHOSEN_STATUS) ){ sendChat("Rage-API", obj.get("name")+" toggling off."); obj.set("status_"+CHOSEN_STATUS, false); CheckUndefined(StrAttr, 'Strength'); CheckUndefined(ConAttr, 'Constitution'); CheckUndefined(HPAttr, 'HP'); CheckUndefined(ACAttr, 'AC'); StrAttr.set("current", parseInt(StrAttr.get("current"))-4); ConAttr.set("current", parseInt(ConAttr.get("current"))-4); HPAttr.set("current", parseInt(HPAttr.get("current"))-(2*parseInt(LevAttr.get("current")))); ACAttr.set("current", parseInt(ACAttr.get("current"))+2); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); } else { sendChat("Rage-API", obj.get("name")+" toggling on."); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); CheckUndefined(StrAttr, 'Strength'); CheckUndefined(ConAttr, 'Constitution'); CheckUndefined(HPAttr, 'HP'); CheckUndefined(ACAttr, 'AC'); obj.set("status_"+CHOSEN_STATUS, true); StrAttr.set("current", parseInt(StrAttr.get("current"))+4); ConAttr.set("current", parseInt(ConAttr.get("current"))+4); HPAttr.set("current", parseInt(HPAttr.get("current"))+(2*parseInt(LevAttr.get("current")))); ACAttr.set("current", parseInt(ACAttr.get("current"))-2); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); } } } }); } });
So now is not giving me any error, but i need to check where to put the str mod and con mod. Will post later the full script, but thank you very much for your help Jordan, I very much appreciate it. S
1609777287

Edited 1609777315
Jordan C.
Pro
API Scripter
Nice! and no problem, I was just about to comment that it doesn't look like you can edit the AC bonus directly but you can create your own misc AC field which you did! Sorry I wasn't familiar with the sheet, probably would have helped to have someone who knew 3.5e to chime in.
So this is what i've done, i had to create some new attributes in order to have it working. Thanks Jordan, that really taught me something. var CHOSEN_STATUS = "strong"; var STRATTR = "str-misc"; var CONATTR = "con-misc"; var HPATTR = "hitpoints"; var ACATTR = "miscac3bonus"; var LEVATTR = "level"; on("chat:message", function(msg) { if (msg.type == "api" && msg.content.indexOf("!Rage") !== -1) { _.each(msg.selected, function(objInfo) { var obj = getObj(objInfo._type, objInfo._id); if( obj.get("_type") == "graphic" ){ if( obj.get("_subtype") == "token" ){ var charID = obj.get("represents"); var StrAttr = findObjs({ name: STRATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ConAttr = findObjs({ name: CONATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var HPAttr = findObjs({ name: HPATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var ACAttr = findObjs({ name: ACATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; var LevAttr = findObjs({ name: LEVATTR, _type: "attribute", _characterid: charID }, {caseInsensitive: true})[0]; const CheckUndefined = (v, str) => { if (v === undefined) log(str + ' is undefined'); }; if( obj.get("status_"+CHOSEN_STATUS) ){ sendChat("Rage-API", obj.get("name")+" toggling off."); obj.set("status_"+CHOSEN_STATUS, false); CheckUndefined(StrAttr, 'Strength'); CheckUndefined(ConAttr, 'Constitution'); CheckUndefined(HPAttr, 'HP'); CheckUndefined(ACAttr, 'AC'); StrAttr.set("current", parseInt(StrAttr.get("current"))-4); ConAttr.set("current", parseInt(ConAttr.get("current"))-4); HPAttr.set("current", parseInt(HPAttr.get("current"))-(2*parseInt(LevAttr.get("current")))); ACAttr.set("current", parseInt(ACAttr.get("current"))+2); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); } else { sendChat("Rage-API", obj.get("name")+" toggling on."); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); CheckUndefined(StrAttr, 'Strength'); CheckUndefined(ConAttr, 'Constitution'); CheckUndefined(HPAttr, 'HP'); CheckUndefined(ACAttr, 'AC'); obj.set("status_"+CHOSEN_STATUS, true); StrAttr.set("current", parseInt(StrAttr.get("current"))+4); ConAttr.set("current", parseInt(ConAttr.get("current"))+4); HPAttr.set("current", parseInt(HPAttr.get("current"))+(2*parseInt(LevAttr.get("current")))); ACAttr.set("current", parseInt(ACAttr.get("current"))-2); //log(StrAttr.get("current")+" "+ConAttr.get("current")+" "+ACAttr.get("current")+" "+HPAttr.get("current")+" "+LevAttr.get("current")); } } } }); } });