Hello, Im am creating a sheet the has some buttons that change the value other inputs. Like the health bar. when you click the button the it will automatically add to the HP value. it works great. Now i'm trying to add some limits to it, such as a may value that the button will not exceed. Example My Max HP is 46 and i only too 4 damage before a long rest. I recover 16 HP per long rest so when i click the long rest button i don't want the Hp to exceed 46. At the moment if i was down 4 hp and i clicked the Long Rest button i would have 58 Hp which is above my max. I will add the button im using to add to my HP below. Let me know if you need anything else. Thanks, This is the button am using to add to my HP and a few other fields. It does the same thing for the other fields but i figured if i can fix on i can fix the others. <script type="text/worker"><!-- Long Rest Button - This changes the value of the Hit Dice, HP, Exhaustion Level, and Sanity when the player clicks the long rest button-->
on('clicked:long_rest', function() {
getAttrs(['sanity_recovery', 'current_sanity', 'long_rest_exhaustion', 'current_exhaustion', 'long_rest_hp', 'current_hp', 'level', 'hit_dice'], function(values) {
const level = values.level ||0;
const new_hit_dice = level ||0;
const current_hp = values.current_hp ||0;
const long_rest_hp = values.long_rest_hp ||0;
const new_rest_hp = current_hp + long_rest_hp ||0;
const current_exhaustion = values.current_exhaustion ||0;
const long_rest_exhaustion = values.long_rest_exhaustion ||0;
const new_rest_exhaustion = current_exhaustion - long_rest_exhaustion ||0;
const current_sanity = values.current_sanity ||0;
const sanity_recovery = values.sanity_recovery ||0;
const new_sanity_recovery = current_sanity + sanity_recovery ||0;
setAttrs({hit_dice: new_hit_dice});
setAttrs({current_hp: new_rest_hp});
setAttrs({current_exhaustion: new_rest_exhaustion});
setAttrs({current_sanity: new_sanity_recovery});
});
});
</script>