
Right, so I figured this would be a quick and simple thing to learn API with but I am starting to pull out my hair. The idea goes like this; I wanted to make an API to convert this:
!Heal @{target|token_id} HP 1d8+1 (or even [[1d8+1]] doesn't really matter either way)
And make it check to see the characters current HP, compare it to its maximum. Take the value of the roll. Add it to the current. And make sure it doesn't go over the characters max for a quick and easy healing API using the targeting system for a party healer.
This is how far I got.
What it spits out when I do it:
Now, when everything is said and done I try and do the rollresult, and it always crashes. Everything everywhere I've read about this says to do it this way and I have no idea what I'm doing wrong. Please someone help me. Also, I know it probably looks like crap. I'm a novice to java, and this is my first hand-made API.
!Heal @{target|token_id} HP 1d8+1 (or even [[1d8+1]] doesn't really matter either way)
And make it check to see the characters current HP, compare it to its maximum. Take the value of the roll. Add it to the current. And make sure it doesn't go over the characters max for a quick and easy healing API using the targeting system for a party healer.
This is how far I got.
var Healspell = Healspell || {}; on("chat:message", function (msg) { //log(msg.content); if (msg.type != "api") return; var args = msg.content.split(" "); var command = args.shift(); if (command === "!heal") { log(args[0]); var token = getObj("graphic", args[0]); var char_id = token.get("represents"); var attr_name = args[1] var curVal = parseInt(getAttrByName(char_id, attr_name)); var maxVal = parseInt(getAttrByName(char_id, attr_name, "max")); log(!char_id); log(attr_name); log(curVal); log(maxVal); log(args[2]); sendChat('', args[2], function(ops) { log(ops[0]); //var rollresult = JSON.parse(ops[0].content); // log(rollresult); // var total = rollresult.total; // log(total); // outs[0] is a message object containing the results of the die roll in parts[0] // This sendChat message will NOT appear in the actual chat window }); } });Now, I can get everything working until the sendChat part, after that it gets a little wonky.
What it spits out when I do it:
"-JcTj4b-IuhZJ8wNUw-F" false "HP" 45 78 "1d8+1" [{"who":"","type":"general","content":"1d8+1","playerid":"API","avatar":false,"inlinerolls":{}}]
Now, when everything is said and done I try and do the rollresult, and it always crashes. Everything everywhere I've read about this says to do it this way and I have no idea what I'm doing wrong. Please someone help me. Also, I know it probably looks like crap. I'm a novice to java, and this is my first hand-made API.