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

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 : &lt; button type="roll" value="/roll 1d8" name="roll_Alignement"&gt; And how the result of this button can change a text ? I try to use that but... : &lt; input type="text" name="attr_Alignement" value="---" disabled="true" / &gt; My actual result : <a href="https://image.noelshack.com/fichiers/2018/16/1/1523898377-capture.jpg" rel="nofollow">https://image.noelshack.com/fichiers/2018/16/1/1523898377-capture.jpg</a> Someone can help me please ? Thanks&nbsp; !!!
1523900060
Finderski
Pro
Sheet Author
Compendium Curator
For something like that you'd want to create a custom&nbsp; roll template . &nbsp;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.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
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 &lt;label class="sheet-pseudobutton"&gt;&lt;input name="attr_assign_alignment" type="checkbox" value="1" style="display:none;"&gt;&lt;span class="sheet-label"&gt;Roll Alignment&lt;/span&gt;&lt;/label&gt; &lt;input name="attr_alignment" type='text' readonly="true" value=""&gt; Sheetworker &lt;script type="text/worker"&gt; on('change:assign_alignment',(event)=&gt;{ 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}); }); &lt;/script&gt; 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.
Forum Champion
Sheet Author
Translator
Paul B. said: So, i created a _roll button : &lt; button type="roll" value="/roll 1d8" name="roll_Alignement"&gt; Shouldn't that be a 1d9, with there existing 9 alignements, with True Neutral in the middle?
1523905125
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
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) &gt;&gt;&gt; text_value set to "loyal good" I know the syntax is false but i try to explain my thinks. Thx
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 ^^ <a href="https://image.noelshack.com/fichiers/2018/16/2/152" rel="nofollow">https://image.noelshack.com/fichiers/2018/16/2/152</a>... <a href="https://image.noelshack.com/fichiers/2018/16/2/152" rel="nofollow">https://image.noelshack.com/fichiers/2018/16/2/152</a>... Thank you
1523965133
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
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.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
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): &lt;label class="sheet-pseudobutton"&gt;&lt;input name="attr_assign_alignment" type="checkbox" value="1"&gt;&lt;span class="sheet-label"&gt;Roll Alignment&lt;/span&gt;&lt;/label&gt; &lt;input name="attr_alignment" type='text' readonly="true" value=""&gt; &lt;script type="text/worker"&gt; on('change:assign_alignment',(event)=&gt;{ 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}); }); &lt;/script&gt;
1523976637
Finderski
Pro
Sheet Author
Compendium Curator
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): &lt;label class="sheet-pseudobutton"&gt;&lt;input name="attr_assign_alignment" type="checkbox" value="1"&gt;&lt;span class="sheet-label"&gt;Roll Alignment&lt;/span&gt;&lt;/label&gt; &lt;input name="attr_alignment" type='text' readonly="true" value=""&gt; &lt;script type="text/worker"&gt; on('change:assign_alignment',(event)=&gt;{ 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}); }); &lt;/script&gt; Scott, doing that, shouldn't the numbers then be 0-8?&nbsp;
1523980482
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
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): &lt;label class="sheet-pseudobutton"&gt;&lt;input name="attr_assign_alignment" type="checkbox" value="1"&gt;&lt;span class="sheet-label"&gt;Roll Alignment&lt;/span&gt;&lt;/label&gt; &lt;input name="attr_alignment" type='text' readonly="true" value=""&gt; &lt;script type="text/worker"&gt; on('change:assign_alignment',(event)=&gt;{ 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}); }); &lt;/script&gt; Scott, doing that, shouldn't the numbers then be 0-8?&nbsp; 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: &lt;label class="sheet-pseudobutton"&gt;&lt;input name="attr_assign_alignment" type="checkbox" value="1"&gt;&lt;span class="sheet-label"&gt;Roll Alignment&lt;/span&gt;&lt;/label&gt; &lt;input name="attr_alignment" type='text' readonly="true" value=""&gt; &lt;script type="text/worker"&gt; on('change:assign_alignment',(event)=&gt;{ 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}); }); &lt;/script&gt; Thanks for catching that Finderski
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 ! <a href="https://image.noelshack.com/fichiers/2018/16/3/152" rel="nofollow">https://image.noelshack.com/fichiers/2018/16/3/152</a>... I begin to understand how javascript works ;) Really thanks you ! Now i'l try to desable the chekbox when he is cheked first time.