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

Custom Roll Parsing not passing to Turn Tracker

1659975193
MAMS Gaming
Pro
Sheet Author
I'm enjoying using Custom Roll Parsing for calculating totals on my character sheet, and when that value is sent to the chat, it works great. When I add  &{tracker} the value sent to the Turn Tracker is the total before the Parsing, even though it sends the total after the Parsing to the Chat. I thought I had a brilliant solution by having the Parsing send 2 rolls like:     ...     setAttrs({"temp_value": total});     finishRoll(results.rollId,{total: total}); }); startRoll("&{template:default} [[@{temp_value} &{tracker}]]", (results) => {finishRoll(results.rollId);}); Unfortunately, the 2nd startRoll triggers before the 1st finishRoll. (This also leaves a black line in the chat, but I can solve that seperately) My next attempt was to put in a delay, to insure that the 2nd startRoll triggers later. setTimeout(function() {     startRoll("&{template:default} [[@{temp_value} &{tracker}]]", (results) => {finishRoll(results.rollId);}); }, 3000); Now, the 2nd startRoll doesn't trigger at all. Sigh. I don't know what I'm doing wrong there, or if I'm even on the right track. Any help would be appreciated, thank you.
1659982416

Edited 1659982713
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yes, the turn tracker only gets the value that the chat actually rolls. Your solution of two rolls is the correct way to solve this. From the incomplete code snippet that you shared, it looks like you're using the callback version of startRoll , and have run afoul of callback hell. Simply do the following: put the 2nd startRoll call inside the first one, right after the finishRoll replace @{temp_value}  with total  like so: startRoll(`&{template:default} [[${total} &{tracker}]]`, (results) => {finishRoll(results.rollId);}); Note that this also means you don't need to store the total value in a temp attribute value using the setAttrs, unless you're using that for something else on the sheet. As a sidenote, I highly recommend using the async/await pattern with startRoll instead of the callback pattern. The code that results from using async/await is cleaner and easier to read, and startRoll is the only place we can use it in sheetworkers. Not sure what the entirety of your code looks like, but doing this would look something like this: As a note, your final attempt with the setTimeout failed because we can't do any personal asynchronous code with sheetworkers because it breaks the link between the sheetworker and the active character sheet. EDIT: edited the instructions for how to fix to reflect the OP use of setAttrs to store the total value in an attribute for use later.
1659994253
MAMS Gaming
Pro
Sheet Author
That worked! Thank you very much. You were right, the only thing I needed setAttrs for was to pass it to the next startRoll. I'm self taught, so I may have missed some things that seem obvious to other people. I guess the $ dollar sign is for local values. Is there a reason you switched from quotation to backticks? I'm about to try a few things to get rid of the black line that appears when sending a roll to the tracker without sending it to chat. Do you already have a method for that? I'm assuming an empty roll template.
1659996433

Edited 1659996480
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Heh, most of us sheet authors are self taught MAMs, so you won't find any of us judging you for that. The backticks and ${...} stuff is template literals , an alternative to string concatenation. For the second startRoll, send it as an API message (prepend the message with ! ). This does not require that a game have access to API scripts.
1659997475
MAMS Gaming
Pro
Sheet Author
Good Stuff. A single !  instead of writing up a whole new template. Works for me. I'm reading about template literals now. I'm sure I'll find a way to incorporate more of them before too long. Thanks again!
1660000658
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
MAMS Gaming said: I'm reading about template literals now. I'm sure I'll find a way to incorporate more of them before too long. Pretty much anywhere that you're doing something like: "String starts and has " + dynamicContent + " that is the value of a variable" Just change it to template literals: `String starts and has ${dynamicContent} that is the value of a variable` Makes the code way easier to read. I have yet to find a use for tag template functions though.