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

Correct way to get character sheet attributes.

Hi, Having trouble getting character sheet attributes.  Using getAttrByName(charid, "dexterity") never gets the right value. Neither of these work. findObjs({ _type: "attribute", _characterid: charId }).filter((att) => att.get("name") == "dexterity"); findObjs({ _type: "attribute", _characterid: charId }).filter((att) => att.name == "dexterity"); getSheetItem(charId, "dexterity"). This does work however the sandbox likes to randomly change back to "Default" and this only works on "Experimental", so I need a solution that'll work in both.  It needs to work for the 2024 and 2014 5e sheets.  Any ideas? All the documentation I could find for any of this is outdated and doesn't work anymore. 
1756562238
GiGs
Pro
Sheet Author
API Scripter
findObjs returns an array, so you'd need to grab the first  item in that array, like findObjs({ _type: "attribute", _characterid: charId }).filter((att) => att.name == "dexterity")[0]; Can you point out which documentation doesn't work? I have never used to 2024 sheet, so I don't know if it uses different coding.
1756562790
timmaugh
Forum Champion
API Scripter
GiGs is right about the first issue, which is knowing that you're going to get an array from findObjs()... but just to correct something in GiGs explanation, you *do* need the .get() syntax for properties like "name": findObjs({ _type: "attribute", _characterid: charId }).filter((att) => att.get("name") == "dexterity")[0]; Also, Beacon sheets (like the 2024 sheet) don't really have functional attributes. That sheet has a single attribute ("store") which contains all of the data for the sheet. You can add other attributes to it, but they are not retrievable in the current implementation. More's the pity. For a beacon sheet, you should use the getSheetItem function as discussed in this article ,  however, that *will* introduce async timing into your code, so be aware.
1756571449
GiGs
Pro
Sheet Author
API Scripter
Thank you for that correction, Tim.
1756627884

Edited 1756638982
GiGs said: Can you point out which documentation doesn't work? On the roll20 help center page here, which I assume in the roll20s official documentation? <a href="https://help.roll20.net/hc/en-us/articles/360037772793-API-Objects#API:Objects-UsingtheNotes,GMNotes,andBiofieldsAsynchronous" rel="nofollow">https://help.roll20.net/hc/en-us/articles/360037772793-API-Objects#API:Objects-UsingtheNotes,GMNotes,andBiofieldsAsynchronous</a> It straight up tells you to use a function that doesn't work. Then they say "be sure to also look at" the Character Sheet documentation that links to a dead page.&nbsp; <a href="https://help.roll20.net/hc/en-us/articles/360037773113" rel="nofollow">https://help.roll20.net/hc/en-us/articles/360037773113</a> For a beacon sheet, you should use the getSheetItem function as discussed in this article ,&nbsp; however, that *will* introduce async timing into your code, so be aware. I do use that, however it only works in the "Experimental" sandbox, and the game keeps swapping back to "Default".&nbsp; Roll20 really do not make it easy to build on their platform.&nbsp;
1756650274
timmaugh
Forum Champion
API Scripter
Kiingy said: GiGs said: Can you point out which documentation doesn't work? On the roll20 help center page here, which I assume in the roll20s official documentation? <a href="https://help.roll20.net/hc/en-us/articles/360037772793-API-Objects#API:Objects-UsingtheNotes,GMNotes,andBiofieldsAsynchronous" rel="nofollow">https://help.roll20.net/hc/en-us/articles/360037772793-API-Objects#API:Objects-UsingtheNotes,GMNotes,andBiofieldsAsynchronous</a> It straight up tells you to use a function that doesn't work. Then they say "be sure to also look at" the Character Sheet documentation that links to a dead page.&nbsp; <a href="https://help.roll20.net/hc/en-us/articles/360037773113" rel="nofollow">https://help.roll20.net/hc/en-us/articles/360037773113</a> That first page is specifically for the Notes, GMNotes, and Bio fields from a character sheet, which have to be accessed asynchronously. I don't want to underestimate your comfort with JS (I don't know anything about you), so I'll just say for fullness of the explanation: async access of these fields can make it look like it failed. Consider: let charBio; let character = getObj("character", "-JMGkBaMgMWiQdNDwjjS"); character.get("bio", bio =&gt; { &nbsp; &nbsp; charBio = bio; }); log(charBio); When this runs and charBio is logged to the script log panel, it will be empty because the code immediately continues past the async callback. The charBio variable will be filled, eventually, but not in any kind of time where you would need to use it. Is this akin to what you were doing? And if so, do you see the dilemma? Or maybe you can post your code where you tried to use this function so we can see what is going on? Also, the link that is broken probably just went to a sheet like this one , discussing how character sheets *also* use the same sandbox as scripts. Not really necessary for you to consider when building a script... that's something more applicable to sheet builders and those-who-would-troubleshoot an odd error, knowing that it could attribute to the sheet rather than your script. Kiingy said: For a beacon sheet, you should use the getSheetItem function as discussed in this article ,&nbsp; however, that *will* introduce async timing into your code, so be aware. I do use that, however it only works in the "Experimental" sandbox, and the game keeps swapping back to "Default".&nbsp; There's a memory problem with the xBox that they're working on. They're working on it in terms of Beacon being the would-be standard-bearer of the Roll20 experience, buuuuut..... API is always a lower priority than the wider VTT experience, so make of that timeline what you will. =/
timmaugh said: That first page is specifically for the Notes, GMNotes, and Bio fields from a character sheet, which have to be accessed asynchronously. I don't want to underestimate your comfort with JS (I don't know anything about you), so I'll just say for fullness of the explanation: async access of these fields can make it look like it failed. Consider: let charBio; let character = getObj("character", "-JMGkBaMgMWiQdNDwjjS"); character.get("bio", bio =&gt; { &nbsp; &nbsp; charBio = bio; }); log(charBio); When this runs and charBio is logged to the script log panel, it will be empty because the code immediately continues past the async callback. The charBio variable will be filled, eventually, but not in any kind of time where you would need to use it. Is this akin to what you were doing? And if so, do you see the dilemma? Or maybe you can post your code where you tried to use this function so we can see what is going on? I'm familiar with javascript, The function just grabs the initiative data of a character async function getInitiative(charId) { &nbsp; &nbsp; const [bRaw, tRaw, dRaw] = await Promise.all([getSheetItem(charId, "initiative_bonus"), getSheetItem(charId, "init_tiebreaker"), getSheetItem(charId, "dexterity")]); &nbsp; &nbsp; // do things &nbsp; &nbsp; return { bonus, tie }; } That works fine in Experimental but not in Default of course, and the issue of it swapping back has been a problem for months at this point.&nbsp;&nbsp; So I need something that'll work in the Default sandbox with the new 2024 sheets. But I'm guessing that's not possible?
1756817832
timmaugh
Forum Champion
API Scripter
Kiingy said: So I need something that'll work in the Default sandbox with the new 2024 sheets. But I'm guessing that's not possible? Accurate. At this point the Default Sandbox is sitting around, laughing at getSheetItem() the Gray like...