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

Can I Pull Attr Data Using Sheetworkers From Different Sheet?

Like the question asks, can I use sheetworker's getattr to pull attribute data from a different character? Or more broadly, is there a specific syntax or formatting to pull info from a different chacater? For context, I'm trying to make a single "ship" that all player's character sheets can see and edit during gameplay.
1653386976

Edited 1653387033
GiGs
Pro
Sheet Author
API Scripter
The official answer is no. Character sheets are meant to be isolated from each other, and getAttrs, setAttrs and other functions work only for their given character. It was discovered a while back that there is an undocumeted character ID attribute, and there might be a way to get it and work with it. But you'd need a way to identify the ship character which is non-trivial, and work with at least one extra level of of asynchronous functions which is also not trivial. Maybe Scott or someone else has done this kind of thing, but it's unsupported and isn't guaranteed to be free of bugs. Since you're a Pro user, the "proper" way to do this would be to use a script like ChatSetAttr to update the ship character's attributes.
1653390133

Edited 1653390414
Oosh
Sheet Author
API Scripter
The second part of the first trick over here has a 'heal target' example of changing attributes on another sheet. As GiGs said, this requires using a bunch of tricks which are well and truly unsupported, so I'd be iffy about applying them to a sheet for submission. But if it's a custom sheet for your own game, it might be worth a try. For science! One big caveat - the async functions required for this to work do not play nicely with the API sandbox. If the ship character_id isn't going to change, I'd find some way of storing that on the player sheets too, otherwise you'll need to prompt for it every time. Another possibility (and probably easier, and less dodgy) is to use another variation on the first trick in that thread. Use CRP to fish the stats from the sheet by name . The player sheet will need an input to record their ship's name. You then throw out a fishing startRoll() with @{shipname|stat1} @{shipname|stat2}, grab the data from the roll, and do whatever you want with it. The fishing roll is invisible, and those stats will need to be stuffed inside tags inside inlinerolls inside template properties, as described in the trick. As long as the players can spell their ship name, it should work, and it shouldn't need any API-breaking activeCharacterID acrobatics. This simpler approach will only work for getting attributes - if you need to set them on another sheet as well, you'll need the full async activeCharacterId framework.
1653392809
GiGs
Pro
Sheet Author
API Scripter
I dont think I want to click this button <button type="action" name="act_test">Uninstall Windows</button>
1653393936
Finderski
Pro
Sheet Author
Compendium Curator
GiGs said: I dont think I want to click this button <button type="action" name="act_test">Uninstall Windows</button> Do it and install Linux. ;)
1653408180
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
As Oosh said, the Roll20Async side does unfortunately break the API sandbox which makes it unusable in my opinion (I really wish it was usable). However, there are two alternatives. If you just need the stat to be used in a roll, you could do what I did for the Starfinder by Roll20 character sheet. The starfinder ship sheet allows users to enter their character names in the various crew slots and then the sheet's sheetworkers construct the macros for a given roll so that it calls the correct attribute from that character's sheet. This could of course be swapped if you need characters to call attributes from the ship sheet. Additionally, with custom roll parsing this would actually become easier to setup as the macro could be assembled in real time. The second option is something that only became possible with the advent of Custom Roll Parsing (CRP). It is however a very hacky method that I'm not sure I'd ever use on a sheet that is going to be used for the public. This method would let you actually use another sheet's attribute values in calculations. What you'd need for the hacky CRP method: A button to trigger a recalculation of values dependent on the other sheet. This will trigger a CRP function A place to input the name of the sheet(s) to pull data from Your CRP function, which will send a roll to chat that will call the values needed from the other sheet. This roll would start with an exclamation ( ! ) to stop it from showing up in chat. In general, option 2 would look something like this (untested code for demo purposes only): <button type="action" name="act_pull-data">Update data from other sheet</button> <input type="text" name="attr_connected_character" value=""> <input type="number" name="attr_attribute_to_get" value="10"> <input type="number" name="attr_attribute_to_set" value=""> <script type="text/worker"> const getOtherAttribute = async function(charName,attrName){ debug('entering extractQueryResult'); let queryRoll = await startRoll(`!{{query=[[0[response=@{${charName}|${attrName}}]]]}}`); finishRoll(queryRoll.rollId); return queryRoll.results.query.expression.replace(/^.+?response=|\]$/g,''); }; on("click:pull-data",()=>{ getAttrs(['connected_character'],async (attributes)=>{ if(!attributes.connected_character){ return; } const setObj = {}; setObj.attribute_to_set = await getOtherAttribute(attributes.connected_character,'attribute_to_get');//Returns a string version of the attribute. Convert to number as needed. setAttrs(setObj); }); }) </script> I use something similar to this in several sheets to query the user for options they want to use for a given roll. The reason I wouldn't recommend doing this in a sheet meant for the repo is that this method will screw with users' ability to up arrow to see their last roll. The last roll may be one of these messages to get another character's data instead of the roll they actually sent to chat. This is also why, regardless of whether the sheet is meant for production or not, I'd recommend locking this update behind a button; otherwise you could wind up with literally hundreds of these hidden messages polluting the chat archive as they'd be sent every time an attribute related to the connected value was updated. And, finally, you could reverse the function as well and have the update button work so that it calls an action button on another sheet to inject data into that other sheet. You'd want to use some of the discoveries from Oosh's Adventures with startRoll for that .