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 .
×

Automatically disabling buttons when player doesn't have enough mana?

I'm working on a sheet for an upcoming game (Unity). Part of the project is letting the players add their powers (think 4e-style abilities) to a repeating list. These powers have "mana" costs associated with them (every class resource is called something different, but let's call it mana for simplicity's sake). Each power has a checkbox (which I plan on styling like a button) which deducts the cost from the player's mana pool. I also have functions watching to make sure the values don't go below 0 or above the max.  My issue is that I want to disable the "spend power" checkbox when the player doesn't have the mana to spend. For instance, I have the made-up power Justice set up on my sheet. It has a cost of 3, and the player only has 2 mana. In this situation, I want the spend mana button to be greyed out/disabled/whatever. I can't figure out how to make this work - a lot of the CSS hide/show/disable tricks require the player to actively click on a checkbox, but I want this to happen automatically (I have a loop that checks all of the powers any time the player's mana value changes, to re-evaluate what is affordable and what isn't). Any help would be greatly appreciated!
1532603741
Finderski
Pro
Sheet Author
Compendium Curator
You could have a sheetworker that watches the mana pool and on change cycle through all the powers and any power that has a higher mana cost than exists in the pool, hide the checkbox and display a span that looks like the checkbox, but is a different color...
That's sort of what I'm doing, but how do you hide/disable buttons via sheet workers? As far as I know, all you can do is change attribute values, and not any properties of the elements. If there was a way to check boxes via sheet workers, that would work, but changing the value doesn't trigger :checked elements in the CSS etc.
1532655107

Edited 1532655174
GiGs
Pro
Sheet Author
API Scripter
You have a CSS rule that hides the styled field or div based on the status of a checkbox. It's described on the CSS Wizardry page of the wiki
1532684660
Finderski
Pro
Sheet Author
Compendium Curator
Eric S. said: That's sort of what I'm doing, but how do you hide/disable buttons via sheet workers? As far as I know, all you can do is change attribute values, and not any properties of the elements. If there was a way to check boxes via sheet workers, that would work, but changing the value doesn't trigger :checked elements in the CSS etc. Setting a checkbox value does make it checked, as long as the value is the value of the checkbox. For example: <input type="checkbox" value="1" name="attr_tester" /> Using a sheet worker to set tester = 1 will make that checkbox checked, setting to a value other than 1 will make it unchecked. With that checkbox being checked, the CSS will trigger—at least it does for me.   NOTE : You want to be sure to give the checkbox a value for when it is checked.  If you don't specify a value, then that may be why you aren't seeing it as checked. I've also found it easier to make sure the value is something other than 0.
Well, crap. I thought I'd already tried out the checkbox value check/uncheck thing, but I suspect I wasn't setting the value properly when setting it up in the first place. Thanks for all your help!