
I am trying to write a script that rolls the HP for each token I drag onto the board. I have the dice to roll and some defaults for the HP and HP_max. The pertinent variables with example values are: npc_HP_hit_dice = '2d6+8' npc_HP = 15 npc_HP_max = 15 I have created a character with an NPC character sheet (D&D 5e if you think it is pertinent), and assigned it a default token with values for the HP and HP max. Then, I added this script on("add:graphic", function(obj) {
// log('obj'); log(obj);
var token = getObj('graphic', obj.id);
// log('token'); log(token);
var character = getObj('character', token.get('represents'));
// log('character'); log(character);
var npchd = getAttrByName(character.id, 'npc_HP_hit_dice');
// log('npchd'); log(npchd);
var roll = "/r " + npchd;
// log('roll'); log(roll);
sendChat('', roll, function(res) {
var result = res[0].content;
result = JSON.parse(result);
// log('result'); log(result);
var rolledHP = result.total;
log('rolledHP'); log(rolledHP);
log('obj.id'); log(obj.id);
token.bar3_value = rolledHP;
token.bar3_max = rolledHP;
log('token2'); log(token);
});
});
Please excuse all the log()s, I am debugging.