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 .
×
Create a free account

[Help] Setting Attributes on 5e OGL sheet

When trying to set certain attributes using setWithWorkers(), the sheet doesn't seem to update as expected. So I created a very basic test script to illustrate my problem: on('chat:message', function(msg) { if (msg.type === 'api' && msg.content.search(/^!new\b/) !== -1) { createSheet("Testing"); const char = findObjs({_type: "character", name: "Testing"})[0]; setAttributeWithWorkers(char.id, "npc", 1); setAttributeWithWorkers(char.id, "strength_base", 19); } }), createSheet = function(name) { const checkSheet = findObjs({_type: 'character', name: name}); if (checkSheet[0]) { return; } else { createObj('character', {name: name, archived: false}); } }, setAttributeWithWorkers = function(charid, attr, val) { let attribute = findObjs({_type: "attribute", _characterid: charid, name: attr})[0]; if (!attribute) { createObj("attribute", {name: attr, current: val, characterid: charid}); } else { attribute.setWithWorker("current", val); } }; Basically add the script to a campaign with the 5e OGL sheet and type the command !new.  The script simply: Creates a new character sheet named Testing (works as expected) Sets the npc attribute to 1, making this an npc sheet (works as expected) Sets the strength_base attribute to 19 (doesn't exactly work as expected) Here is the screenshot, notice the value shows 19, but the sheet still show 10: If I go into the sheet and put the cursor in the STR field (where it says 19) then tab out of it, the STR updates on the sheet below.  This obviously isn't helpful when trying to use the API to completely setup a sheet, because if you have to open the sheet and tab through all the fields to get it to update... well I might as well manually enter them. Also, is there any possible way via the API to use the "drop_" attributes to mimic importing a monster via the compendium?
1507675150

Edited 1507675212
Jakob
Sheet Author
API Scripter
Observation: in your setAttributeWithWorkers function, if the attribute does not exist yet, setWithWorker() is never called. So it's not so surprising that it would not work, and even wouldn't work if you called it again, since then the value of the attribute is not actually changed. You probably want to create an attribute with an empty value first, then  set it via setWithWorker(). Regarding the compendium import, I don't think it's possible.
@Jakob - I see now what you mean, it’s pretty obvious when you point it out.  Let me see if it works by creating the blank attribute then setting with workers.