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 set a maximum cap to an attribute without using the API?

An example to my question would be: I have a defense value of 95% but i do not want the defense to ever go above 75%. Didn't found much about that topic. Sorry bad English.
1560647143
GiGs
Pro
Sheet Author
API Scripter
Are you creating your own character sheet? If so, then the answer is yes, If you are using a pre-made character sheet, I believe the answer is no, but you can make macros that limit the skill to 75 for roll purposes, using the drop highest modifier:  {your-skill, 75}dh1 .
Yes i am creating my own character sheet, and the simple solution that does not seem to work is the <input max="x">. And wouldn't drop highest discard anything that rolls above "75"?
1560649346
GiGs
Pro
Sheet Author
API Scripter
I was suggesting there that you roll against your skill: if your skill is 50, {50,75}dh1 becomes 50. If your skill is 95, {95,75}dh1 becomes 75. You could use to ensure that whatever the skill it is never treated as above 75, either by including it directly in your roll button values, or by using a secondary attribute to hold the "effective value" and all rolls use the effective attribute value. Another way to do it if you want to actually limit it on the character sheet, would be to use a sheet worker. With a sheet worker you can make sure that if a value above the limit is entered, it gets set to the limit. You could also use a sheet worker to replace the {skill,75}dh1 calculation. How to do it depends on exactly what you need. I could see you having a hard limit of 75, that cant be exceeded, or an effective  limit. Can players get to 95 say, but if they suffer a -30 modifier, they are at 65, but are otherwise limited to 75? 
1560649667
GiGs
Pro
Sheet Author
API Scripter
My last post might be a little incoherent. Here are some questions to narrow down what you need: Is this maximum for just one rating (defence) or is it universal for all ratings? Is it based on another value which can itself be above the limit? Do you have a button that uses this value, and what is the roll?
1. Just for some specific ratings (defense being the most important). 2. Yes, a whole array of them. 3. Yes, but by 'what is the roll' do you mean the actual macro? PS: I am very much interested the the sheet/worker solution (if you have example(s) on how its used i would love it/them!).
1560657978

Edited 1560659798
GiGs
Pro
Sheet Author
API Scripter
I asked about the roll just in case I needed to see it to understand how you are using the stat, but t's okay, I dont think I need it. If you give the exact stat names and formula used to calculate them, I could give the sheet worker you need. But here's in imaginary proof of concept: Imagine you have three stats, str, dex, and int. Defence is the average of those three stats, with a maximum value of 75. Here's one way to build the  sheet worker you'd use to calculate that: on("change:str change:dex change:int sheet:opened", function() { getAttrs(["str", "dex", "int"], function(values) { const str = +values.str||0; const dex = +values.dex||0; const int = +values.int||0; let score = Math.round((str + dex + int)/3); score = Math.min(score,75); setAttrs({ defence: score });     }); }); The first line sets up a watcher. Whenever any of the stats change, the sheet work runs. Sheet workers have no direct access to the character sheet. They don't know what stats exist. So the second line uses the getAttrs function to grab the attributes named, and store them in a variable called values. Now the sheet worker has access to them. The three const lines extract the attribute scores from the values object, and associate them with variables names str, dex, and int. The three steps described above are the core steps you will do over and over when making sheet workers. First set up a watcher to monitor the sheet, then grab the values you need to manipulate. Now you can get around to do the actual operation the sheet worker is for. In this case, I create a variable named score, and calculate its value from those attributes. Now in the final step that every sheet worker will have (setAttrs), we save that calculated score to the character sheet. This assumes you have an attribute named defence.  You should be able to use this to create your own sheet workers-  just change the stat references. One thing to be careful of: Make sure all your attributes are named in lower case, and avoid using a dash within their names. For instance, don't use defence-score, you'd use defence_score or defencescore instead. You can use upper case letters and dashes, but you have to use slightly more complicated synatx than I've described above so it's better just to not do that. In summary, this is the basic layout of a sheet worker. Every worker will look like this.  on("change:stat1 change:stat2 sheet:opened", function() { getAttrs(["stat1", "stat2"], function(values) { const stat1 = +values.stat1||0; const stat2 = +values.stat2||0; // perform some calculation here setAttrs({ destination_stat: calculation_result });     }); }); This assumes you are doing numerical calculations. If your stats dont need to be numbers, the const lines will be simpler, like this: const stat1 = values.stat1; const stat2 = values.stat2; The code in the full worker above (with the + ||0) makes sure the input is a number, and if it cant recognise it as a number, it sets a default value of 0. If you have several calculated stats, I can probably create a single function to make them all in one go, instead of having to create a separate sheet worker for each. But I'd need the details of how they are calculated, including attribute names. Almost forgot:  Sheet workers must be put inside a script block. If your html doesnt have the code below, add it to the end of your character sheet: <script type="text/worker"> </script> All the sheet workers you create go inside that block.
Wow, thank you very much! You are a life saver. <3
1560659838
GiGs
Pro
Sheet Author
API Scripter
You're welcome! By the way, my sheet worker had a little error on the Math.min line, I just corrected it.