Advertisement Create a free account

New Character Sheet --- How use a _roll resut to determinate a text ?

1523898460

Edited 1523898860
Hello everyone, By advance, sorry for my bad english, i'am french and i try hard to be understandable. I actually try to create a custom Star Wars character sheet but, how can i use a _roll button result to determinate a text ? To be exacte, i try to do an automatic alignement selector button where 1 = Lawful good 2 = Lawful neutral 3 = Lawful evil [...] 9 = Chaotic evil So, i created a _roll button : < button type="roll" value="/roll 1d8" name="roll_Alignement"> And how the result of this button can change a text ? I try to use that but... : < input type="text" name="attr_Alignement" value="---" disabled="true" / > My actual result : https://image.noelshack.com/fichiers/2018/16/1/1523898377-capture.jpg Someone can help me please ? Thanks  !!!
1523900060
Finderski
Pro
Sheet Author
For something like that you'd want to create a custom  roll template .  Then within that template you can evaluate the roll and output different text. You want to use some of the Helper Functions (such as {#rollTotal()}, etc)
1523901824

Edited 1523902080
Scott C.
Pro
Sheet Author
API Scripter
I think what you are trying to do is change the actual value on the sheet in response to a roll. That's not possible without an API script. What you could do to sidestep the issue is use sheetworkers to randomly assign the value when a pseudobutton is clicked. Something like this: HTML <label class="sheet-pseudobutton"><input name="attr_assign_alignment" type="checkbox" value="1" style="display:none;"><span class="sheet-label">Roll Alignment</span></label> <input name="attr_alignment" type='text' readonly="true" value=""> Sheetworker <script type="text/worker"> on('change:assign_alignment',(event)=>{ const convertAlign = { '1':'LG', '2':'NG', '3':'CG', '4':'LN', '5':'N', '6':'CN', '7':'LE', '8':'NE', '9':'CE' }; setAttrs({alignment:convertAlign[randomInteger(9)]},{silent:true}); }); </script> Note that the randomInteger function in the Roll20 sandbox uses the same quantum roll technology as the dice rolls in chat.
Ok, thanks ! I will try yours solution, i'am a novice in html and css but i'l try. ;-)
1523905110
Andreas J.
Pro
Sheet Author
Paul B. said: So, i created a _roll button : < button type="roll" value="/roll 1d8" name="roll_Alignement"> Shouldn't that be a 1d9, with there existing 9 alignements, with True Neutral in the middle?
1523905125
Scott C.
Pro
Sheet Author
API Scripter
Paul B. said: Ok, thanks ! I will try yours solution, i'am a novice in html and css but i'l try. ;-) Heh, we all start somewhere. Heck, I only started learning html css a bit ago.
Andreas J. said: Shouldn't that be a 1d9, with there existing 9 alignements, with True Neutral in the middle? Yes you are right ^^ I have an other question, can i use if / else in html ? Something like : if(last_roll_result=4) >>> text_value set to "loyal good" I know the syntax is false but i try to explain my thinks. Thx
1523914485
Author X
Pro
Sheet Author
You can use if-then in JavaScript, which is what the Sheet Worker uses. However, Scott C's script is already converting numbers to text using a table, so it's not necessary. You just need to change the short text like "LG" to longer text like "Lawful Good" (or "Loyal Good" if you prefer).
Hello, I try to use Scott C's script but i don't understand why, that don't work ^^ https://image.noelshack.com/fichiers/2018/16/2/152... https://image.noelshack.com/fichiers/2018/16/2/152... Thank you
1523965133
Scott C.
Pro
Sheet Author
API Scripter
Your second link gives me an error when trying to access it. Can you give some more details on how it doesn't work?
Image links work for me. Well, i have a title and a white bloc where i can't write.
1523968160

Edited 1523968277
Scott C.
Pro
Sheet Author
API Scripter
Ah, it looks like randomInteger() is not defined in the sheetworker sandbox. Well, that's annoying. We can do this instead (in the API this would be equivalent to using quantum roll in chat - not sure about in the sheetworker side of things): <label class="sheet-pseudobutton"><input name="attr_assign_alignment" type="checkbox" value="1"><span class="sheet-label">Roll Alignment</span></label> <input name="attr_alignment" type='text' readonly="true" value=""> <script type="text/worker"> on('change:assign_alignment',(event)=>{ const convertAlign = { '1':'LG', '2':'NG', '3':'CG', '4':'LN', '5':'N', '6':'CN', '7':'LE', '8':'NE', '9':'CE' }; setAttrs({alignment:convertAlign[Math.ceil(Math.random()*9)]},{silent:true}); }); </script>
1523976637
Finderski
Pro
Sheet Author
Scott C. said: Ah, it looks like randomInteger() is not defined in the sheetworker sandbox. Well, that's annoying. We can do this instead (in the API this would be equivalent to using quantum roll in chat - not sure about in the sheetworker side of things): <label class="sheet-pseudobutton"><input name="attr_assign_alignment" type="checkbox" value="1"><span class="sheet-label">Roll Alignment</span></label> <input name="attr_alignment" type='text' readonly="true" value=""> <script type="text/worker"> on('change:assign_alignment',(event)=>{ const convertAlign = { '1':'LG', '2':'NG', '3':'CG', '4':'LN', '5':'N', '6':'CN', '7':'LE', '8':'NE', '9':'CE' }; setAttrs({alignment:convertAlign[Math.ceil(Math.random()*9)]},{silent:true}); }); </script> Scott, doing that, shouldn't the numbers then be 0-8? 
1523980482
Scott C.
Pro
Sheet Author
API Scripter
Finderski said: Scott C. said: Ah, it looks like randomInteger() is not defined in the sheetworker sandbox. Well, that's annoying. We can do this instead (in the API this would be equivalent to using quantum roll in chat - not sure about in the sheetworker side of things): <label class="sheet-pseudobutton"><input name="attr_assign_alignment" type="checkbox" value="1"><span class="sheet-label">Roll Alignment</span></label> <input name="attr_alignment" type='text' readonly="true" value=""> <script type="text/worker"> on('change:assign_alignment',(event)=>{ const convertAlign = { '1':'LG', '2':'NG', '3':'CG', '4':'LN', '5':'N', '6':'CN', '7':'LE', '8':'NE', '9':'CE' }; setAttrs({alignment:convertAlign[Math.ceil(Math.random()*9)]},{silent:true}); }); </script> Scott, doing that, shouldn't the numbers then be 0-8?  Ah, no, but it also wouldn't do what I was aiming for. It would give 0-9 (which is still incorrect). So it should be this then: <label class="sheet-pseudobutton"><input name="attr_assign_alignment" type="checkbox" value="1"><span class="sheet-label">Roll Alignment</span></label> <input name="attr_alignment" type='text' readonly="true" value=""> <script type="text/worker"> on('change:assign_alignment',(event)=>{ const convertAlign = { '1':'LG', '2':'NG', '3':'CG', '4':'LN', '5':'N', '6':'CN', '7':'LE', '8':'NE', '9':'CE' }; setAttrs({alignment:convertAlign[(Math.floor(Math.random()*9) + 1)]},{silent:true}); }); </script> Thanks for catching that Finderski
1523980689
Author X
Pro
Sheet Author
Math.ceil means fractions between 0 and 9 will be rounded up, so 1-9 is appropriate. (Technically there is a veeeery small chance Math.random() could return exactly zero and that would throw an error).
1524039498

Edited 1524039656
Hello everyone ! That works ! https://image.noelshack.com/fichiers/2018/16/3/152... I begin to understand how javascript works ;) Really thanks you ! Now i'l try to desable the chekbox when he is cheked first time.