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 .
×

getSheetItem throws an error

Hello, I'm trying to get oriented with mod development with nexus sheets, and I'm running into some problems.  The documentation briefly mentions that if you want to work with demiplane, you need to use getSheetItem/setSheetItem, and reference the advanced->attributes tab of the chracter for the attribute names. A discord member pointed me towards libSmartAttributes, which seems to handle getting data from the correct place, however I'm still facing issues. This is the small script I am testing with: let charId = char.id; let charName = char.get("name"); let level = await libSmartAttributes.getAttribute(charId, "level"); let output = "Character: " + charName + "\n"; output += "Level: " + level + "\n"; And this is the error I'm facing: TypeError: Cannot read properties of undefined (reading 'level')     at getComputed (file:///home/node/d20-api-server/api.js:755:29)     at getSheetItem (file:///home/node/d20-api-server/api.js:881:20)     at Object.getAttribute (apiscript.js:2529:34)     at handleChat (apiscript.js:2457:50)     at file:///home/node/d20-api-server/src/pubsub2.js:42:46     at Map.forEach (<anonymous>)     at PubSub.publish (file:///home/node/d20-api-server/src/pubsub2.js:42:35)     at Timeout.processChatQueue [as _onTimeout] (file:///home/node/d20-api-server/api.js:1472:14)     at listOnTimeout (node:internal/timers:569:17)     at process.processTimers (node:internal/timers:512:7) Does anyone have any insight on this?
1773589584
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hi Joshua! A couple of things spring to mind. 1. I'm under the understanding that Demiplane sheets are not directly available to the API. Beacon sheets are. Can you tell me where the Demiplane reference you found is? 2. In case this is a miscommunication, and you meant Beacon: Are you running your scripts using the Experimental server? The Default server does not recognize those commands. 3. Without knowing more about the specifics, it's also possible that "level" is not an exposed attribute.
1773591328
The Aaron
Roll20 Production Team
API Scripter
I looked into this issue and will add some guards to prevent the crash.  What I can say is that either: The sheet you have in the game does not support computeds (there's no computeds, the lookup is what is crashing) The code is running before the computeds get loaded (there would be computeds, but the code is executing before they can be read asynchronously from the sheet). In either case, you should be defering your code until the ready event fires, so be sure you are wrapping your code in a check for the ready event: on('ready',()=>{ // YOUR CODE HERE });
1773593847

Edited 1773594167
1. In  this  document, under FAQs, number 4 ( Can I use Mod Scripts in games that include Demiplane character sheets?) , it states:  Mod scripts must utilize the "getSheetItem" and "setSheetItem "async functions instead of the "getAttrs" and "setAttrs" functions.' 2. Experimental server is set, yes.  3. The level is available as shown in the above image. This is the attributes page, as specified by that same FAQ above.  Some attributes may have different names or interactions between the sheets. You can see available attributes on Demiplane Sheets via the “Advanced Tools” tab in the character sheet. @The Aaron, it's being run when the user selects a token and runs a chat command. It's not running on startup. The script is here:  test.js
1773596850
The Aaron
Roll20 Production Team
API Scripter
Ok.  I took a look.  I think that section on Mod Scripts has a bit of copy pasta from Beacon.  The intent is that getSheetItem()/setSheetItem() would be used to access Demiplane sheet making use of the same underlying system that Beacon sheets do, but I don't believe that work has completed yet. Mod scripts must utilize the "getSheetItem" and "setSheetItem "async functions instead of the "getAttrs" and "setAttrs" functions. Your script looks fine.  I would still wrap the whole thing in a ready event unless you need to process objects as they are being created.  I'll get that bugfix into the API server in one of the next updates so this crash doesn't happen again.