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

If else statements and for loops????

1584455797
Skyeris
Pro
Sheet Author
Compendium Curator
trying to work on a custom sheet and i cannot figure out how to implement if else statements or for loops. does any one have any idea how?
1584458441

Edited 1584458790
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
in what context? in a macro that a roll button is sending? That's not possible. Or if you mean in the sheetworker to drive the sheet, it's just basic javascript code. Can you share the code that is giving you issues? Edit: Here's a basic javascript if/else: if(value < 1){     setAttrs({affected_attribute:0}); }else if(value > 3){     setAttrs({affected_attribute:value*2}); }else{     setAttrs({affected_attribute:value}); }  and a basic for loop (note that personally I avoid for loops like the plague): let v = 0; for(let i = 0;i<4;i++){     v+= (i + 1)*2; }
1584465471
Skyeris
Pro
Sheet Author
Compendium Curator
In the sheetworker. I don't have code atm, though let me test your code. I dont know if i was doing something completely wrong
1584465586
Skyeris
Pro
Sheet Author
Compendium Curator
How would you insert the script in the sheet?
1584465939
Andreas J.
Forum Champion
Sheet Author
Translator
Skyeris said: How would you insert the script in the sheet? <a href="https://wiki.roll20.net/Building_Character_Sheets#Sheet_Workers_Scripts" rel="nofollow">https://wiki.roll20.net/Building_Character_Sheets#Sheet_Workers_Scripts</a>
1584465944

Edited 1584466215
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You insert code in the html code using the script tag: &lt;script type='text/worker'&gt; &nbsp;&nbsp;&nbsp;&nbsp;//Code here &lt;/script&gt; only use ONE script tag. All your code goes in that single script tag. The script tag can be anywhere in your code, but common practice is to put it at the end of the html. I'd recommend reading the building character sheets and&nbsp; sheetworkers wiki pages. Edit: Also, note that my proto code above will do pretty much nothing (except possibly trigger an error in the console) as it lacks any listener context or other necessary pieces of a functional sheetworker.
1584473095
GiGs
Pro
Sheet Author
API Scripter
If you stat what specifically you want to happen, (like, for example, "I want to change their bloodied status attribute when hit points drop below half"), we can give specific tips that are a lot more helpful.