Gotcha, so you're trying to trigger the "roll" on one sheet and get data from another. I think what you are going to want to just use the straight cross sheet communication trick; essentially you treat startRoll as a POST request or the vanilla JS fetch function. You'll need the following hidden buttons (button names can of course be changed as you see fit): HTML <button type="action" name="act_receive" style="display:none;></button>
<button type="action" name="act_receive-info" style="display:none;></button>
<!-- and then the button you are actually clicking of course --> JS // adapted from K-scaffold, which itself adapted from Oosh's Adventures in StartRoll forum post
// utility to BASE64 encode/decode data for passing data inside ability button calls.
const RE = {
chars: {
'"': '%quot;',
',': '%comma;',
':': '%colon;',
'}': '%rcub;',
'{': '%lcub;',
},
escape(data) {
return typeof data === 'object' ?
`KDATA${btoa(JSON.stringify(data))}` :
`KSTRING${btoa(data)}`;
},
unescape(string) {
const isData = typeof string === 'string' &&
(
string.startsWith('KDATA') ||
string.startsWith('KSTRING')
);
return isData ?
(
string.startsWith('KDATA') ?
JSON.parse(atob(string.replace(/^KDATA/,''))) :
atob(string.replace(/^KSTRING/,''))
) :
string;
}
};
// utility for sending the cross sheet communication.
const send = async function(charRef,data,buttonName = 'receive'){
const dataString = RE.escape(data);
// Note that the character name attribute call is essential. It essnetially jumpstarts the target sheet's connection with the database to ensure that the attribute data will actually be available to getAttrs
// The character ID call that is done below may not jumpstart as it is treated a little differently from character name.
const roll = await startRoll(`!@{${charRef}|character_name}%{${charRef}|${buttonName}||${dataString}}&{noerror}`);
finishRoll(roll.rollId);
};
on('clicked:get-info', () => {
getAttrs(['character_name''attributes to get on gm sheet'],async (attrs) =>{
// we can get non numerical data out of rolls by storing them in the roll tag.
const roll = await startRoll('!{{query=[[0[response=@{character_id}]]]}}');
finishRoll(roll.rollId);
// extract the character id of the target character from the roll tag.
const targetID = roll.results.query.expression.replace(/^.+?response=|\]$/g,'');
send(targetID,{
from: attrs.character_name,
action: 'some key that your recipient function will know how to respond to'
})
})
})
// then we also listen for "clicks" of the hidden receive button.
on('clicked:receive',async (event) => {
// the originalRollId is the information that we added after that double || above.
const data = RE.unescape(event.originalRollId);
getAttrs(['character_name','attributes you will need to reply to the request'],async (attrs) => {
// easiest method is to just return the attrs object you get from getAttrs
send(data.from,{
from: attrs.character_name,
attrs
},'recieve-info');
});
});
// then we also listen for "clicks" of the hidden receive-info button.
on('clicked:receive-info',(event) => {
const data = RE.unescape(event.originalRollId);
getAttrs(['character_name','attributes you will need in order to work with the passed data'], (attrs) => {
// work with sheetworkers as you normally would, except you now have `data.attrs` which is a record of the attribute data that the other sheet passed back.
});
});
You can see this technique live in the Walking Dead character sheet with its embedded NPCs, Locations, and Factions.