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

[Help] Question about input values

1508614543
Phillip G.
Plus
Sheet Author
I am trying to set the default value of an input field to the value of another input field. So far the only way this has worked for me is if the field is disabled. Am I doing something wrong or does Roll20 just not do what I want? Code presented below for clarification: <span class="sheet-table-data-left"><input title="DEX-bonus" type="number" name="attr_DEX-bonus" value="0"></span> <span class="sheet-table-data-center"><input title="Acrobatics" type="number" name="attr_Acrobatics-npc" value="@{DEX-bonus}"></span> I have left out the code I think is inconsequential to this discussion. In the case presented above, the value of @{DEX-bonus} does not transfer to @{Acrobatics-npc} and is not displayed on the sheet. The idea here is that the default bonus for skills should be the bonus of a related ability, but if other bonus apply, then the skill bonus can be changed to be the total bonus. TIA for any help
1508615229
Jakob
Sheet Author
API Scripter
Doesn't work just like that, but it can be done with sheet workers.
1508616689
Phillip G.
Plus
Sheet Author
that figures...
1508620439
Phillip G.
Plus
Sheet Author
Okay, so I want to add sheet workers to the sheet. Where should I go after reading the wiki? It wasn't very helpful, probably because I don't know the code.
1508621447

Edited 1508621479
Seth
Sheet Author
Sheetworkers are essentially javascript as I understand it. They have certain limitations, but what crosses which line (text/worker to translation to API) seems to have to do with what kind of js you are using (sort of). I'm no wizard, but if you just need a script to migrate values, I think I actually have one on one of my tables.
1508670625

Edited 1508672632
Jakob
Sheet Author
API Scripter
That's actually kind of a hard question. You can look at generic Javascript tutorials;, but you have to keep in mind that most of them teach DOM manipulation (i.e. manipulating the HTML on a web page), which sheet workers cannot  do; instead, they run in a sandbox and can only interact with the outside world via the event handlers and functions demonstrated in the wiki article. Most importantly they can only respond   to events (via on("change:blabla", function () { /*...*/}); they can get the values of attributes  (via getAttrs) to perform further manipulations, get all section IDs in a repeating section  (via getSectionIDs), and then finally set the values of attributes  (via setAttrs) - there are other functions, but these are the ones you will use the most. In the end, (almost) every change that sheet workers make to a sheet is going to be via a setAttrs call like this (very simple example): on('change:strength', function (event) {   setAttrs({     strength_mod: Math.floor((parseInt(event.newValue) - 10)/2)   }); }); Perhaps take a look at a few sheets that use (simple) sheet workers and try to learn by example.
1508680062
Phillip G.
Plus
Sheet Author
Thanks again for the insight Jakob. With the sheet mostly complete, I should have some time to dive into this.