Hey guys! So I know that the D&D 2024 character sheet is different in a lot of ways, but how do you set an attribute on a character—ANY attribute— using API ? I have been messing around to do this for a while with no success. This is kind of important to the what I want to do with my campaign. To test the weirdness and try for a work-around, I created a macro tool to send an API command. The macro reads like this: !aat!@{target|character_id}!?{Stat Name?}!?{New Value?} This calls this script in API: const getOrCreateAttribute = (name, cid) => findObjs({
type: 'attribute',
characterid: cid,
name: name
}, {caseInsensitive: false})[0] || createObj('attribute',{
characterid: cid,
name: name
});
on("chat:message", function(msg) {
//////////////////////////////////////////////////////////////////
// GET ID OF THE EFFECTED CHRACTER/OBJECT
var sMsg = msg.content||"!!-O_yNYcqS5IfvLryXeyQ"; // <-- Safety character ID
var aMsg = sMsg.split("!");
var sID = aMsg[2]||"";
var sAlt = "-O_yNYcqS5IfvLryXeyQ";
if(sID == "" || sID == undefined || sID == null || sID.indexOf("character_id") > -1){sID = sAlt;}
// END OF GET ID SEGMENT
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
// ADJUST AN ATTRIBUTE TEST
if(sMsg.indexOf("!aat!") !== -1)
{
let sAttr = aMsg[3]||"";
let sVal = aMsg[4]||""; let nVal = parseInt(sVal)||0;
let nPass = true;
if(sID == "-O_yNYcqS5IfvLryXeyQ"){nPass = false;}
if(sAttr == ""){nPass = false;}
if(sVal == ""){nPass = false;}
if(nPass == true)
{
////////////////////////////////////////////////////////////////////
// SET THE ATTRIBUTE ///////////////////////////////////////////////
let oAttr = getOrCreateAttribute(sAttr,sID);
oAttr.set("current",sVal);
////////////////////////////////////////////////////////////////////
// GM ALERT THAT CHANGE WAS PROCESSED //////////////////////////////
sSay = "/w gm Stat Change Initiated. Stat: "+sAttr+", New Value: "+nVal;
sendChat("API",sSay);
}
}
// END OF ADJUST AN ATTRIBUTE TEST
//////////////////////////////////////////////////////////////////
}); The resulting gm feedback tells me that the code is running all the way through, but no attribute change occurs. So what am I doing wrong? Any help would be appreciated! Michael