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

Update the value of a roll button with sheetworker

1680290116

Edited 1680290168
Maïlare
Pro
Sheet Author
API Scripter
Hello, Because my character sheet have some tabs and to make finding information faster on my character sheet, I have make a resume page with all the important informations of the sheet for the players. On this page I display inter alia the repetitive sections of weapons and their roll buttons. But I want to conditionned the roll expression if the weapon effect is different of 'Aucun' (none). How can I change the value of the roll button ? Here is my code : < fieldset class = "repeating_weapons" >      < div class = "dark_row" >          < button   type = "roll" style = " margin-left:0px;line-height:10px;height:20px;margin-bottom:2px;" title = "Combat corps à corps" name = "roll_Melee" value = "@{expressionRoll}" ></ button >          < input class = "textbox" type = "text" name = "attr_ArmeNom" readonly = "readonly" style = " width:150px;margin-left: 0px;" />          < input class = "textbox-stat" type = "number" name = "attr_ArmeDegNv" style = " width:40px;text-align:center;" readonly = "readonly" > d10+ </ input >          < input class = "textbox-stat" type = "number" name = "attr_ArmeDegModNv" style = " width:40px;text-align:center;" readonly = "readonly" />          < input type = "hidden" name = "attr_ModDegEffetResume" value = "" />          < input type = "hidden" name = "attr_EffetResume" value = "" />          < input type = "hidden" name = "attr_PourcentageResume" value = "" />          < input type = "hidden" name = "attr_NbTourResume" value = "" />          < input type = "hidden" name = "attr_expressionRoll" value = "" />      </ div > </ fieldset > on ( "change:repeating_weapons:ModDegEffet change:repeating_weapons:Effet change:repeating_weapons:Pourcentage change:repeating_weapons:NbTour" , function () {         getAttrs ([ "repeating_weapons_ModDegEffet" , "repeating_weapons_Effet" , "repeating_weapons_Pourcentage" , "repeating_weapons_NbTour" ], function ( values ) {             var modDeg = parseInt ( values . repeating_weapons_ModDegEffet );             var effet = values . repeating_weapons_Effet ;             var pourcentage = parseInt ( values . repeating_weapons_Pourcentage );             var nbTour = parseInt ( values . repeating_weapons_NbTour );             var roll = '' ;             const comparateur = 'Aucun' ;             if ( effet === comparateur ) {                 roll = '&{template:degats} {{perso=@{Name} }} {{name=@{ArmeNom} }} {{RollDegats=[[@{ArmeDegNv}d10+@{ArmeDegModNv}]] }} {{Roll=[[1d100]] }}' ;             } else {                 roll = '&{template:degats} {{perso=@{Name} }} {{name=@{ArmeNom} }} {{RollDegats=[[@{ArmeDegNv}d10+@{ArmeDegModNv}]] }} {{Roll=[[1d100]] }} {{TotalDegats=[[@{ArmeDegNv}d10+@{ArmeDegModNv}+@{ModDegEffetResume}]] }} {{effet=@{EffetResume} }} {{pourcentage=[[@{PourcentageResume}]] }} {{RollTour=[[1d@{NbTourResume}]] }}' ;             }             setAttrs ({                 repeating_weapons_expressionRoll : roll ,                 repeating_weapons_ModDegEffetResume : modDeg ,                 repeating_weapons_EffetResume: effet ,                 repeating_weapons_PourcentageResume: pourcentage ,                 repeating_weapons_NbTourResume: nbTour             });         });     });
1680330470

Edited 1680383786
GiGs
Pro
Sheet Author
API Scripter
The value of a rollbutton is not accessible to sheet workers-  you can't change it at all. You can modify an attribute with a sheet worker, and then reference that attribute ion your roll button. In your example, you'd just change the text of the expressionRoll attribute. Without knowing the specifics of what you want to do , I can't be more precise. By the way, your sheet worker has a subtle mistake, that many people don't realise is a mistake. Your event line includes upper case characters: on("change:repeating_weapons:ModDegEffet change:repeating_weapons:Effet change:repeating_weapons:Pourcentage change:repeating_weapons:NbTour", function() { Change this to: on("change:repeating_weapons:moddegeffet change:repeating_weapons:effet change:repeating_weapons:pourcentage change:repeating_weapons:nbtour", function() { I don't know if the current documentation of sheet workers warns against this, but the old documentation used to. All attribute names on that line (and that line is the only place it matters) should be changed to lower case. A lot of the time, the code will appear to work notrmally, but one day it will stop working without warning. Changes to those attributes will not be detected, and you will have no idea waht's wrong. This is what's wrong: that line should only contain lower-case letters.
1680347907
Maïlare
Pro
Sheet Author
API Scripter
Hello GiGs, Thanks I doesn't know this. I will do this and test.