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

Roll Template for Custom Character Sheet

Hello everyone,


Question:

- Could someone show me an example of a way to have a name or button on a character sheet that stores the variable between sessions that can be easily referenced that uses the Roll Template for chat?


I was following the example provided by the Roll20 API guide and I think I was following it alright, yet I am confused where to place the Macro. I'd like the Macro to be part of the sheet so it doesn't need to be added as an addon (if I'm understanding that correctly). I do have a lot of web dev front end experience. I simply need to wrap my head around how things work here on Roll20.

I figured, while I'm asking, if someone would be kind enough to show how they are storing local or global variables, that would be nice.

I tried making custom attribute names and either I’m doing something wrong or that doesn’t work. For example, “attr_character_dexterity” will create a stored variable on the sheet on the last page. However, if I did a different name, for instance, “attr_character_role”, that doesn’t get created on the last page. I tried referencing it with code similar to “@{attr_character_role}“ and it doesn’t seem to do anything. Could that be because I need to use JavaScript to make the code update live on the sheet? I thought the prebuilt features of the sheet syntax wound work. Maybe I’m misunderstanding something simple… [Hope I did code examples correctly, currently doing a repost and I added to this message via my phone. I had posted a version of this question on a different forum and was recommended here.]


For my ease, can you make the example make sense, so pretend you are making an attack, heal, or some other dice roll. Context helps me associate the knowledge.


Much appreciated any help you can provide,


Res



P.S. If someone feels extra kind, I was curious how the DnD character sheets have the lock/unlock feature for data entered in text fields. I figured I could likely do that using Javascript. If there is a pre-built way to do that, I am curious, otherwise I will be looking to do it that way.

December 05 (2 years ago)

Edited December 05 (2 years ago)
Kraynic
Pro
Sheet Author

If this is for a custom character sheet, you probably don't want to follow anything that has to do with the api, but rather the articles about building character sheets.  Javascript sheetworkers are a bit different than the api, in that they are available to anyone of any subscription level, but api/mod calls are only available in games created by a pro subscriber with the correct api scripts/mods installed.

As far as attributes showing on the Attributes & Abilities tab, blank values don't show up there and they won't show there until they have a value.  They (blank attributes) also can break macros.  This is why there many sheets will use a default value for an attribute if it is referenced from a roll button.

I'm not aware of the D&D sheet locking text.  It will show/hide input fields.

There is a lot of info on sheet building on the wiki.  The start point is here: https://wiki.roll20.net/Building_Character_Sheets

That page has links to other, more focused, articles including ones on buttons, macros, roll templates, javascript sheetworkers, etc.


December 06 (2 years ago)

Edited December 06 (2 years ago)
GiGs
Pro
Sheet Author
API Scripter

Im not siure what you're asking in the first step. There are so many different game systems, and so many ways of writing a macro, it would require too much explanation to make our own imaginary macro. If you supply very specifically what roll you want and how it works, we can show you how to do it.


To add to Kraynics comment about attributes & abilties: if you are creating a characetr sheet, ignore the attributes list there. It's a legacy feature that exists purely for people who aren't using character sheets (or want to create their own custom attributes). Many character sheet attributes don't show up there, and in the past it was buggy when changing attributes that did show there and were also on the character sheet. So, I repeat, if you are using character sheets, ignore that section.


You also refer to the attr_character_dexterity and attr_character_roll attributes. But just to be clear, the attr_ part is not part of the attribute name. That is only visible when creating character sheets, and would be shown on the character sheet list (which you shouldnt be using, remember) as character_dexterity and character_roll. The only place you use the attr_ part is during sheet design, in the html.


You'll find information on the wiki under Building Character Sheets, and on my site which shows explicitly how to build every sheet element.


December 10 (2 years ago)

Edited December 10 (2 years ago)

Kraynic, thank you for the suggestion. I have been using those resources.


GiGs, thank you for sharing your website. I will later this week be looking into it extensively. I'm looking forward to it.


So to clarify, you are saying that the variables stored on the back of a character sheet is an old practice that I shouldn't be following anymore? To be specific with an example. And I will be reading your website, here is my request, if you are so kind to provide a good practiced solution:


Create Role for Character

1. Create a variable (do global / local variables matter on a character sheet?) that stores an INT of a dice rolled by a button (on the sheet). This variable is stored between game/browser sessions and could support a character transfer to a different game.

[example: roll a 1d6 for character role and store the output in variable "character_role"]



2. Reference "character_role" and use an if or switch statement , retrieve a stored variable that gets referenced by comparing number to the "character_role". (wrote a guess below)

if (@{character_role} == 4){ stuff; }

[output in text-field on character sheet is: The Bard]



I did read that using Sheetworkers was a better practice than Auto Calculation. Also from my understanding, the "attr_" part of "attr_character_role" would only be listed when naming the input, not when referencing it.



Random questions: Is there a way to reference each sheet's "character_role" variable outside the sheet? Like a Master Sheet or to have a sheet that references character sheets 1 through 6? I imagine it is getting sheet ID number.

December 10 (2 years ago)
GiGs
Pro
Sheet Author
API Scripter

Regading Attribute List: yes, if you using or creating a character sheet you should ignore that. The only time it is relevant is when players want to create custom attributes that aren't already on the sheet. (And even then, it's better to have a place on the character sheet (maybe a repeating attribute) where players can create their own custom attributes, but how useful that is and how you'd create it depends on the system.)


Sheet workers are a better practice than autocalc attributes, but if you can do everything you need with autocalcs, they are easier to code. Problems start when you try to mix and match, so it's best to use all sheet workers (best option) or all autocalcs (okay option).


I'm not sure exactly what you want to do with your last question. The way Roll20 is set up, it's not meant to allow links between character sheets at design time.

But you can create macros that incorporate a character's sheet name using the @{CHARACTER-NAME|MACRO-NAME} syntax (or @{selected|MACRO-NAME}. These are things you usually create after the sheet is already created, when you know what names the players have chosen for their sheets.

There is a characterid property that you might be able to find and use in some contexts, but it is extremely, extremely undocumented. It's not intended to be used by end-users.


Thank you again for all the help. I have made some progress. I do have a question about the roll templates. I was able to get it working mostly the way I'd like. I have two questions - I'll provide the default code on the Roll20 website for example:

<button type="action" name="act_test">Click me</button>

<rolltemplate class="sheet-rolltemplate-test">
    <div class="sheet-template-container">
        <h1>{{name}}</h1>
        <div class="sheet-results">
            <h4>Result = {{roll1}}</h4>
            <h4>Custom Result = {{computed::roll1}}</h4>
        </div>
    </div>
</rolltemplate>

<script type="text/worker">
    on('clicked:test', (info) => {
        startRoll("&{template:test} {{name=Test}} {{roll1=[[1d20]]}}", (results) => {
            const total = results.results.roll1.result
            const computed = total % 4;

            finishRoll(
                results.rollId,
                {
                    roll1: computed,
                }
            );
        });
    });
</script>

In the <rolltemplate> DIV section, they use the example of "computed::roll1" for the "Custom Result." In my code I have made a "title" variable that is defined before the "finishRoll" is called. I know it works, because I have used the "console.log(title)" to verify that the logic is working correctly. My problem is that I am confused on how to return the STR of "title" to the <rolltemplate> DIV section.

For example:

{{title::roll1}}


That doesn't work.


On another note, I was able to use "setAttrs" to change a variable on the sheet based on player interaction with the "on('change:test'..." event. I was trying to figure out a way to do it in event mentioned above, before the finishRoll is called or maybe inside it? I think I'm able to modify it through Macros or having it print the appropriate text to the chat field. I'd prefer to have the code cleaner and have it inside this event if possible. I hope this makes sense. Sometimes when writing your own code it can make sense to you, but when explaining it...the ideas don't always get across.

December 11 (2 years ago)

Edited December 11 (2 years ago)
GiGs
Pro
Sheet Author
API Scripter

One thing that a lot of roll20 examples do is have really bad choices for example names. I cannot emphasise this enough - their choice of variable names is often really, really bad for instructional piurposes, and there is no example where this is more true than in the custom roll parsing. This gets in the way of understanding what you need to understand - they make it more confusing than it needs to be.

So when you have something like this:

<script type="text/worker">
    on('clicked:test', (info) => {
        startRoll("&{template:test} {{name=Test}} {{roll1=[[1d20]]}}", (results) => {
            const total = results.results.roll1.result
            const computed = total % 4;

            finishRoll(
                results.rollId,
                {
                    roll1: computed,
                }
            );
        });
    });
</script>

understand that the word computed here is a variable, and could be almost anything. You could just as easily write this as

<script type="text/worker">
    on('clicked:test', (info) => {
        startRoll("&{template:test} {{name=Test}} {{roll1=[[1d20]]}}", (results) => {
            const total = results.results.roll1.result
            const calculation = total % 4;

            finishRoll(
                results.rollId,
                {
                    roll1: calculation,
                }
            );
        });
    });
</script>

But the word computed in the rolltemplates is NOT a variable and cannot be changed:

<rolltemplate class="sheet-rolltemplate-test">
    <div class="sheet-template-container">
        <h1>{{name}}</h1>
        <div class="sheet-results">
            <h4>Result = {{roll1}}</h4>
            <h4>Custom Result = {{computed::roll1}}</h4>
        </div>
    </div>
</rolltemplate>

To understand what's going on here, each property you pass to a rolltemplate has two values. It's normal value, and a second value, its computed value.

You created the computed value in the finishRoll section of a sheet worker. When you do this:

finishRoll(
                results.rollId,
                {
                    roll1: calculation,
                }
            );

you are saving the variable called calculation, and storing it in the computed property of the roll1 value.

Then in a rolltemplate, you can access the computed property of something by doing this: computed::stat, or in this case computed::roll1


So in place of this

{{title::roll1}}

you would need to use one of these:

{{computed::roll1}}
{{computed::title}}

For both of these, you have have to create computed properties in a prior finishRoll. If you save the computed property for roll1, you'd use the first one.


Remember in rolltemplate, computed:: is not variable, and you use it grab the value you have created in finishRoll. In finishRoll you choose where to save it. In the example you posted it is saved in roll1, so you'd use

{{computed::roll1}}

Hopefully that helps. As I mentioned, Custom Roll Parsing is written in a particularly confusing way.