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 .
×
🍵 What is a cleric’s favorite hot drink? Divini-tea. 🍵
Create a free account

Custom Character Sheet: Show/Enable fields when requirements are met

I am building this character sheet for an RPG I found that some friends and I want to play. You level up skills and attributes by spending points that you get after completing missions and tasks. Each Attribute and Skill has 5 levels, investing a point in a skill increases it by it's next level cost (no proficiency to 1 = 1 point, level 4 to 5 = 5 points) I'd like a + button to appear next to the attributes and skills for which you have enough points to level them up. Is there a way to do this? I'm having no luck so far
1554823661
GiGs
Pro
Sheet Author
API Scripter
You need to use css for this, linked to an attribute value. If the number of points changes per attribute or skill, you are best off creating a hidden attribute for each, which will have a value of 0 or 1. Use a sheet worker to set it to 1, when the number of points is high enough, and 0 when its too low. Then in the CSS, have it set to display:none  when value = 0. I dont have time to post code now, but I believe the technique is covered in the css wizardry page on the wiki.
1554827185

Edited 1554827494
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Relying solely on html/css is going to require a lot of css declarations. This is certainly doable, but if xp has a large, or infinite, number of possible values it won't really be feasible. Instead, I'd recommend a sheetworker driven solution so that you can cut down on the number of css declarations needed: HTML <span>XP</span> <input type='number' name='attr_xp' value='0'> <span>Some Skill Name</span> <input name='attr_skill_name' type='number' value='0'> <input class='skill-add-control' type='hidden' name='attr_skill_name_add_control' value='0'><!--You'll need one of these for each of your skills--> <button class='skill-add' type='action' name='act_add-skill-name'>+</button><!--You'll actually need to style this as you want, I'm just doing the skeleton structure here. Also, note that if you are going to do this in a repeating section, the action button name can't have any underscores in it (other than the one following the "act" keyword of course)--> CSS .sheet-skill-add-control:not([value="1"]) + .sheet-skill-add{ display:none; } Javascript (in <script> tag on html page) let skillNames = ['skill_name']; on('change:xp',(event)=>{ const setObj = {}; getAttrs(skillNames,(attrArray)=>{ _.each(skillNames,(skill)=>{ let nextLevel = attrArray[skill]*1 + 1; if(event.newValue*1 >= nextLevel){ setObj[`${skill}_add_control`] = 1; }else{ setObj[`${skill}_add_control`] = 0; } }); setAttrs(setObj,{silent:true}); }); }); on(`clicked:add-${skillNames.join(' clicked:add-').replace(/_/g,'-')}`,(event)=>{ console.log(event); let skillName = event.triggerName.replace(/^clicked:add-/,'').replace(/\-/g,'_'); getAttrs(['xp',...skillNames],(attrArray)=>{ const setObj = {}; let nextLevel = attrArray[skillName]*1 + 1; setObj[skillName]=nextLevel; setAttrs({xp: attrArray.xp - nextLevel});//Will trigger the on change above. Cascading setAttrs and getAttrs like this is not the preferred method. I'm only doing it here for a quick demo. setAttrs(setObj,{silent:true}); }); }); Note that I've only done one skill here, but this is extensible to any number of skills by simply adding them to the skillNames array at the top of the javascript and maintaining the same skill naming scheme demonstrated in the html above. EDIT: Removed extraneous console.logs EDIT 2: Simplified CSS
Scott C. said: Relying solely on html/css is going to require a lot of css declarations. This is certainly doable, but if xp has a large, or infinite, number of possible values it won't really be feasible. Instead, I'd recommend a sheetworker driven solution so that you can cut down on the number of css declarations needed: ... Thanks a bunch! Works like a charm, on a side note, what would the preferred way be to change the xp value after increasing a skill?
1554841144
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Well, that demo script deducts the xp value after the skill is increased, or at least it's supposed to. If you're going to go for this sort of automation at all, I'd recommend having the whole thing be automated from increasing the skill to deducting the xp. You should probably also have a decrease button for the skill so that people can easily fix mistakes or handle other character changes.
Scott C. said: Well, that demo script deducts the xp value after the skill is increased, or at least it's supposed to. If you're going to go for this sort of automation at all, I'd recommend having the whole thing be automated from increasing the skill to deducting the xp. You should probably also have a decrease button for the skill so that people can easily fix mistakes or handle other character changes. I probably will do that at some point, for now, if mistakes were made, they'll have to go in Attributes & Abilities . I really just needed a working character sheet with some basic functions, your code has helped a lot! It'll also help me make some other features! So thanks a bunch again! I'm starting to get a grasp on how the Sheet Worker works now!