In the example below I have 2 character sheets: 1. Black Bear. There is one token on the page. 2. Goblin. I have three tokens on the page. I have the following macro setup on my character sheet !attackweapon @{wpn_name},@{npc_wpn_total},?{Modifier|0},@{npc_char_name},0,?{Ambush?|No|Yes},@{target|token_id} The API script that is called is as follows on("chat:message", function(msg) {
//This allows players to enter !sr <number> to roll a number of d6 dice with a target of 4.
if(msg.type == "api" && msg.content.indexOf("!attackweapon ") !== -1) {
var params = msg.content.replace("!attackweapon ", "");
var parms_split = params.split(',');
var wpn_val = parms_split[0];
var wpn_skill_total = parms_split[1];
var attack_mods = parms_split[2];
var char_name = parms_split[3];
var ambush_skill = parms_split[4];
var ambush_attack = parms_split[5];
var token_id = parms_split[6];
log(char_name+" - !attackweapon - params: " + params);
log(char_name+" - !attackweapon - wpn_name: " + wpn_val);
log(char_name+" - !attackweapon - wpn_total: " + wpn_skill_total);
log(char_name+" - !attackweapon - modifiers: " + attack_mods);
log(char_name+" - !attackweapon - ambush_skill: " + ambush_skill);
log(char_name+" - !attackweapon - ambush_attack: " + ambush_attack);
log(char_name+" - !attackweapon - token_id: " + token_id);
var target = getObj('graphic', token_id);
log(char_name+" - !attackweapon - target: " + target);
var character = getObj('character', target.get('represents'));
log(char_name+" - !attackweapon - character: " + character);
var target_armour = getAttrByName(character.id, 'main_armour');
log(char_name+" - !attackweapon - target_armour: " + target_armour);
var target_name = getAttrByName(character.id, 'char_name');
log(char_name+" - !attackweapon - target_name: " + target_name);
var resistance = getAttrByName(character.id, 'res_def_total');
log(char_name+" - !attackweapon - resistance: " + resistance);
if (ambush_attack == "Yes") {wpn_skill_total = +wpn_skill_total + +ambush_skill;}
var damage = AT(wpn_val, wpn_skill_total, target_armour, attack_mods, resistance, char_name);
var out_dam = damage[0];
var out_fum = damage[1];
var out_pri = damage[2];
var out_sec = damage[3];
var at_roll = damage[4];
if (out_dam == -1) {
out_message = "With a roll of " + at_roll + " has fumbled.";
sendChat('', "&{template:default} {{name="+char_name+" attacks }} {{Event="+out_message+"}} {{Fumble Message="+out_fum+"}}");
}
else if (out_dam == 0) {
out_message = "With a roll of " + at_roll + " has hit " + target_name;
sendChat('', "&{template:default} {{name="+char_name+" attacks }} {{Event="+out_message+"}} {{Damage="+out_dam+"}}");
}
else {
out_message = "With a roll of " + at_roll + " has hit " + target_name;
sendChat('', "&{template:default} {{name="+char_name+" attacks }} {{Event="+out_message+"}} {{Damage="+out_dam+"}} {{Primary Crititcal="+out_pri+"}} {{Secondary Damage="+out_sec+"}}");
}
};
});
I have put numerous log entries in to locate where the script is failing. This appears to be working fine, however on occasion I get the following error: 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 'id' of undefined
TypeError: Cannot read property 'id' of undefined
at apiscript.js:26:46
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)
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 From the API logs it can be seen that the issue is that the parameter character is not getting populated: "Black Bear - !attackweapon - params: 30,65,0,Black Bear,0,No,-LTAR_ftr_nuLcDP-jwc"
"Black Bear - !attackweapon - wpn_name: 30"
"Black Bear - !attackweapon - wpn_total: 65"
"Black Bear - !attackweapon - modifiers: 0"
"Black Bear - !attackweapon - ambush_skill: 0"
"Black Bear - !attackweapon - ambush_attack: No"
"Black Bear - !attackweapon - token_id: -LTAR_ftr_nuLcDP-jwc"
"Black Bear - !attackweapon - target: [object Object]"
"Black Bear - !attackweapon - character: undefined" If I use the second token I get the same error however I have the following in the API log: "Black Bear - !attackweapon - params: 30,65,0,Black Bear,0,No,-LTARc0nMqt7MUZ2dkUy"
"Black Bear - !attackweapon - wpn_name: 30"
"Black Bear - !attackweapon - wpn_total: 65"
"Black Bear - !attackweapon - modifiers: 0"
"Black Bear - !attackweapon - ambush_skill: 0"
"Black Bear - !attackweapon - ambush_attack: No"
"Black Bear - !attackweapon - token_id: -LTARc0nMqt7MUZ2dkUy"
"Black Bear - !attackweapon - target: [object Object]"
"Black Bear - !attackweapon - character: undefined" From what I read because the token id is different for each of the Goblin tokens, I was of the understanding that I could use a single character sheet loaded onto the page several times. Please can someone confirm what I need to do to make this work?
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #454545}