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 the result from a rollString be used as a variable in my Sheet Worker?

1716421709

Edited 1716422273
Cc
Pro
Sheet Author
Hello, I am attempting to use the result of a rollString as a variable later on in the sheet worker. How would I call for the result? Note this occurs within the same sheet worker. This is what I had in mind (didn't include all the code, just what gets my idea across): ... finishRoll(results.rollId, {     rollsoakdot: totalabs1 }); ... let dot1 = parseInt(results.rollId.rollsoakdot)||0;
1716429893

Edited 1716430097
GiGs
Pro
Sheet Author
API Scripter
I can only guess what you're doing, but after a function is closed, any variables from within it are lost. So if you want to use that variable it would have to be more like this: ... finishRoll(results.rollId, {     rollsoakdot: totalabs1 let dot1 = parseInt(rollsoakdot)||0; ... }); You can include complete code in there, just as you can with stuff inside: getAttrs(['whataver'], values > { // lots of code here }); This is exactly what the finishRoll is for, btw.
1716444111
Cc
Pro
Sheet Author
This is the code. I'm trying to get rollsoakdot to count as a variable for the math after the dice roll, but it didn't work with your suggestion. on("clicked:turn", function() { getAttrs(["dot1","dot2","dot3","stamtax","offbal","heart","stammax","paraltier","paral","speedmax","stamtaxmod","stamtaxinstantmod","bulkcheck","hearttemp","soakenviroreroll","soakenvirototal","driskdr","drisk","absorption","damredbuffdot"], function(values) { let dot1 = parseInt(values.dot1)||0; let dot2 = parseInt(values.dot2)||0; let dot3 = parseInt(values.dot3)||0; let speedmax = parseInt(values.speedmax)||0; let stamtax = parseInt(values.stamtax)||0; let offbal = parseInt(values.offbal)||0; let stammax = parseInt(values.stammax)||0; let heart = parseInt(values.heart)||0; let hearttemp = parseInt(values.hearttemp)||0; let paraltier = parseInt(values.paraltier)||0; let soakenvirototal = parseInt(values.soakenvirototal)||0; let soakenviroreroll = parseInt(values.soakenviroreroll)||0; let driskdr = parseInt(values.driskdr)||0; let drisk = parseInt(values.drisk)||0; let absorption = parseInt(values.absorptionarb)||0; let damredbuffdot = parseInt(values.damredbuffdot)||0; if ((dot1 == "0") & (dot2 == "0") & (dot3 == "0")) { let paraldebuff = (paraltier >= 1) ? 1 : 0; let offbalfinal = (offbal != 0) ? offbal - 1 : 0; let stammath = stammax - offbal - paraldebuff; let stamfinal = (stammath < 0) ? 0 : stammath; setAttrs({ "offbal": offbalfinal }); setAttrs({ "stam": stamfinal }); setAttrs({ "speed": speedmax }); } if ((dot1 >= "1") && (soakenvirototal >= "1")) { if (soakenviroreroll >= "0") { let rollString = "&{template:soakdot} {{name=SoakDot}} {{rollsoakdot=[[[[floor(@{soakenvirototal})]]d6s>@{setsuccesssoak}]]}}"; rollString += "{{rollsoakdotr1=[[@{soakenviroreroll}d6>5]]}}"; startRoll(rollString, results => { const roll = results.results.rollsoakdot.result; const reroll_calculated = results.results.rollsoakdotr1.result; const rerollmin = (soakenvirototal - roll <= 0) ? 0 : soakenvirototal - roll; const reroll = (rerollmin - reroll_calculated <= 0) ? rerollmin : reroll_calculated; const total = dot1 - roll - reroll; const absconst = ((total <= 0) || (absorption <= 0)) ? 0 : 1; const totalfinal = (total <= 0) ? 0 : total; const absorbfinal = (absorption >= 1) ? absorption : 1; const totalabs1 = Math.floor(totalfinal / absorbfinal) + absconst; finishRoll(results.rollId, { rollsoakdot: totalabs1                 let rollsoakdot1 = parseInt(rollsoakdot)||0; }); }); } } let totalabs1 = rollsoakdot1; let dotdr1 = ((dot1 - damredbuffdot) >= 1) ? damredbuffdot : 0; let dotdr2 = ((dot2 - damredbuffdot) >= 1) ? damredbuffdot : 0; let dotdr3 = ((dot3 - damredbuffdot) >= 1) ? damredbuffdot : 0; let dotdr = dotdr1 + dotdr2 + dotdr3; let paraldebuff = (paraltier >= 1) ? 1 : 0; let offbalfinal = (offbal != 0) ? offbal - 1 : 0; let dot1final = (dot1 != 0) ? dot1 - 1 : 0; let dot2final = (dot2 != 0) ? dot2 - 1 : 0; let dot3final = (dot3 != 0) ? dot3 - 1 : 0; let heartmath = heart - totalabs1 - dot2 - dot3 + dotdr; let heartmath2 = heart + hearttemp - totalabs1 - dot2 - dot3 + dotdr; let heartfinal = (heartmath < 0) ? 0 : heartmath; let stammath = stammax - offbal - paraldebuff; let stamfinal = (stammath < 0) ? 0 : stammath; setAttrs({ "offbal": offbalfinal }); setAttrs({ "dot1": dot1final }); setAttrs({ "dot2": dot2final }); setAttrs({ "dot3": dot3final }); if(hearttemp > "0") { let heartfinal = (heartmath2 < 0) ? 0 : heartmath2; if((hearttemp - totalabs1 - dot2 - dot3) <= 0) { setAttrs({ "hearttemp": 0 }); setAttrs({ "heart": heartfinal }); } else { setAttrs({ "hearttemp": hearttemp - totalabs1 - dot2 - dot3 }); } } else { let heartfinal = (heartmath < 0) ? 0 : heartmath; setAttrs({ "heart": heartfinal }); } setAttrs({ "stam": stamfinal }); setAttrs({ "speed": speedmax }); }); });
1716476448

Edited 1716476808
GiGs
Pro
Sheet Author
API Scripter
first, never include multiple setAttrs calls in the same code. You can create a variable to hold the output, like const output = {}; then can add values to it, output.speed = speedmax; And then just do this once, at the very end of your code: setAttrs(output); It will include all the stats you have added to the output variable. Note: where the end of your code is might not be obvious. My guess is after you have finished reorganising the worker, it would be just before the }); inside finishRoll.. Second, remember this, it is vital : outside of the scope of a function, all attributes created in that function are deleted or undefined. That code you have at the end of your function won't work - it all has to be placed inside finishRoll . Also it looks like you have an extra } inside finishRoll - that will break the sheet worker. But that may be me not reading the indentation properly, which is inconsistent.
1716481970
Cc
Pro
Sheet Author
Darn, issue is that 3 different rolls could occur, so I'll have to get creative if I want this to work. Once I get everything working, I'll fix up the code so all those setAttrs aren't overlapping each other.
1716492243
GiGs
Pro
Sheet Author
API Scripter
Something I often say and I'll repeat here: can you describe the mechanic as if I was a player in your dface-to-face game? Don't mantion roll20 or any part of roll20 in your decsription, but do mention game statistics on the paper chracter sheet. It's very likely I'll be able to tell you a way to do it in roll20.
1716522970
Cc
Pro
Sheet Author
I've gotten this part working: "If you are afflicted by "Damage over Time", at the beginning of your turn, you take damage equal to the stacks of DoT that you have, then the DoT counter goes down by 1." Not this part though:   "However, if you have a 'Soak' score specifically for negating DoT damage, you can attempt to decrease how much damage you take at the start of your turn from DoT. Roll a number of d6's equal to your 'Soak DoT' score, and decrease the damage DoT deals this turn by the number of successes from that roll (5's and 6's are successes). I want to automate the damage, since with how much you have to balance in this system, I know some players are gonna forget to decrease their health at the start of their turn. However, that 'Soak' roll complicates the automation I've coded so far.
1716602706
GiGs
Pro
Sheet Author
API Scripter
That's kind of incomprehensible to me. It seems to be explaining only part of what I need to know, and assumes i know the parts that aren't explained but are necessary to understand.