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

Select A Character Character Sheet

Is it possible to create a character sheet that requires you to select a preset character from a drop down menu. Then the preset character information is loaded onto the character sheet. I know some java scripting would be required here, but I don't have a lot of experience. My thought is this: In the the html a drop down menu is created at the top with character names as selections. After that a java script would run and based off the selection it would assign values to different things. For example: Choose a character: [Jeff] [Shelly] [Tony] [Jess] Player selects Jess Javascript runs and sees that Jess was chosen. Then values are assigned using if statements (if jess is selected, varCharacter = Jess, varHP = 54, etc.). I hope this gets my point across. But what I want to know is if this is even possible to do with the Roll20 character sheets and what that might look like if possible.
1614297489

Edited 1614297814
GiGs
Pro
Sheet Author
API Scripter
Yes you can do this with a sheet  worker (javascript).  The dropdown cant be updated once the character sheet is created. So you'd be fixed with the same set of characters for ever. The best use for this is for things like selecting a weapon, armour, horse, even monster stats, etc - things with fixed stats that generally dont change once the game starts. Here's code that illustrates the process. First you'd need a select to choose the option: <select name="attr_character">     <option selected>None</option>     <option>Jeff</option>     <option>Shelly</option>     <option>Tony</option>     <option>Jess</option> </select> Then in your sheet workers section, you need a special variable that contains the names of the characters and the attributes and values you want to update. That would look something like const characters = {     None: {str: 10, dex: 10, cha: 10},     Jeff: {str: 11, dex: 19, cha: 10},     Shelly: {str: 12, dex: 8, cha: 10},     Tony: {str: 13, dex: 7, cha: 10},     Jess: {str: 14, dex: 6, cha: 10}, }; The characters object  contains the str, dex, and cha attributes for each character. Note, your character sheet must  have attributes named str, dex, and cha. The None option sets defaults. It's important to have a "none selected" option. You could put that variable inside the following sheet worker, or before it in your script block. Then you'd use this in a sheet worker like: on('change:character', () => {     getAttrs(['character'], values => {         const character = values.character;         const stats = characters.hasOwnProperty(character) ? characters[character] : characters.None;         setAttrs(stats);     }); }); This code checks for when the character is changed, and fills the stats variable with the stats of that character, and setAttrs saves the character to the character sheet. Does this answer your question?
Awesome!!! Thank you, this is exactly what I was looking for!
1614305782
GiGs
Pro
Sheet Author
API Scripter
Great! I've posted several variants of this technique on the forums before, but your question gave me the opportunity to write the most succinct version so far. It'll be very handy to refer people back to when the topic comes up again. 
So one other question for the values of the character, am I able to insert an image specific to each character as well as create buttons that differ from character to character? 
1614370291
GiGs
Pro
Sheet Author
API Scripter
maybe, if you are more specific about what they should do. You cant change the images on the bio tab, but you can have image placeholder in the html, and change what image gets displayed based on the character selected (easiest way to do that is with CSS). How should the buttons differ?
Awesome, that answers the image question and how I was thinking it need to go. As for the buttons each character has three buttons that all roll slightly different off of three different tables. For example the thre rolls are Technical, Brawn, and Sight. each character has a roll for each of these that is slightly different. One  might be rolling twice off table 2 and once off table three, and this will be different from the other characters. I hope that makes sense.
1614372058
GiGs
Pro
Sheet Author
API Scripter
You can do that too. If they have very different setups per character, then doing it with the CSS Wizardry trick swap areas is likely the wayt o go:&nbsp; <a href="https://wiki.roll20.net/CSS_Wizardry#Swap_Visible_Areas" rel="nofollow">https://wiki.roll20.net/CSS_Wizardry#Swap_Visible_Areas</a> As with the image changing trick, you'd need to set up a type="hidden" input with the same name as the select, so that when the select is changed, that hidden input gets the same value. CSS can only respond to the value of hidden inputs. An alternative: if there is always the same number of button rolls, you can link the value to an attribute, and have it set the same way as my earlier example. Like this - first set up the button and hidden attribute: &lt;button type="roll" name="roll_first" value="@{firstbutton}"&gt;Some Display Text&lt;/button&gt; &lt;input type="hidden" name="attr_firstbutton" value=""&gt; Now add the hidden attribute value to the attributes set by the sheet worker: const characters = { &nbsp; &nbsp; None: {str: 10, dex: 10, cha: 10, firstbutton: "/roll 1d20+4"}, &nbsp; &nbsp; Jeff: {str: 11, dex: 19,&nbsp;cha: 10, firstbutton: "/roll 1d20+7"}, &nbsp; &nbsp; Shelly: {str: 12, dex: 8,&nbsp;cha: 10, firstbutton: "/roll 2d6"}, &nbsp; &nbsp; Tony: {str: 13, dex: 7,&nbsp;cha: 10, firstbutton: "/roll 1d100*10"}, &nbsp; &nbsp; Jess: {str: 14, dex: 6,&nbsp;cha: 10, firstbutton: "&amp;{template:default} {{name=A Roll}} {{The Roll=[[1d20+4]]}}"}, }; So what happens here is you you change the character, and the firstbutton attribute gets set with the above value. And when you click the button, it uses that attribute value, and makes the roll listed.
Sweet, Thank you so much, this is exactly the answers I'm looking for!
1614429881
Finderski
Pro
Sheet Author
Compendium Curator
GiGs said: Yes you can do this with a sheet&nbsp; worker (javascript).&nbsp; The dropdown cant be updated once the character sheet is created. So you'd be fixed with the same set of characters for ever. This bit confused me...why wouldn't he be able to update the drop down? In my head it seems like it would be as simple as adding another option and updating the script with the new option details...what am I missing?
1614450331
GiGs
Pro
Sheet Author
API Scripter
I mean that it cant be updated dynamically, while players are using it. You can only update it by directly editing the sheet's code.
1614461654
Finderski
Pro
Sheet Author
Compendium Curator
Ahh...gotcha. :)