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

Character sheets, JS, API, worker scripts? I'm green but I did a thing

1495902582

Edited 1495903182
Let me just tell You that I have no idea about this stuff at all, still figuring this out, I started few hours ago because I need to do something specific in a Star Wars D6 character sheet I'm currently working on and I can't achieve with just plain HTML. I've seen that we can't use JS in sheets due to security reasons but then again we can use worker scripts and I have no idea what these are? What's the difference? Same goes with API. Anyway after hours of struggling I did this:&nbsp; <a href="https://www.w3schools.com/code/tryit.asp?filename=" rel="nofollow">https://www.w3schools.com/code/tryit.asp?filename=</a>... And I guess it's not working because it's all JS but seeing how does that work You may have an idea of what I'm going for. So... how would You do it so it would work on roll20? Edit: As for why I went with JS anyway: " Sheet Worker Scripts are an advanced feature of the Character Sheets system which allows the sheet author to specify JavaScript which will execute during certain events, such as whenever the values on a sheet are modified ." It's just very confusing for me.
1495903700
The Aaron
Pro
API Scripter
This is a longer conversation than I can have on my phone. :) in short, the API and Sheet Workers are both scripts written in JavaScript and executed in a limited and restricted environment. In both cases, they are automating things that could be done manually by players. Sheet workers run in the context of a specific character sheet, and get activated by events happening on that sheet. E.g. A player enters their strengths which causes a sheet worker to calculate the modifiers based on the new strength value.&nbsp; API scripts run in the context of the Game as a whole and get activated by events happening when the game is changed by players. E.g. A player moved their token and an API Script checks to see if the token is now in a trap and whispers to the GM.&nbsp;
1495904145

Edited 1495904978
So as i understand it.. it should work just fine then? It's limited to change things only in the sheet. The idea here is simple, a player selects (using a checkbox) a lightsaber form he just learned or he already knows so it's selectable for him in a dropdown menu next to his weapon, if he doesn't know it then it's grayed out and cannot be selected (disabled by a script). Why it doesn't work then? As you can see it works just fine on w3schools site. What did I do wrong here? Edit: And before anyone asks: yes, in the sheet the script sits in &lt;script style="text/worker"&gt;&lt;/script&gt;
1495905037
The Aaron
Pro
API Scripter
Because the API and Sheet worker scripts execute in a limited sandbox. It's not like writing JavaScript in a web page, it's more like writing Node.js Modules.&nbsp; You don't have access to document or window. You have a limited number of functions you can call which let your code execute when an event occurs. At that point, you can use a specific subset of functions to make changes on objects you can access.&nbsp;
1495905391

Edited 1495905414
So... I can use only functions that are listed there&nbsp; <a href="https://wiki.roll20.net/Sheet_Worker_Scripts" rel="nofollow">https://wiki.roll20.net/Sheet_Worker_Scripts</a> ? That's... kind of a let down. Is then what I'm trying to do even possible?
1495906010
The Aaron
Pro
API Scripter
It is possible (with some minor changes), but require a paradigm shift if you're used to direct manipulation. Probably best to look at some sheets with the functionality you want, then look at how then did it. You can also post in character sheets and as for help.&nbsp;
As I said in the title I'm completely green when it comes to JS as I started trying it out merely few hours ago, I have no idea what&nbsp;paradigm shift is and google tells it's an album.
1495912970
The Aaron
Pro
API Scripter
Sorry. Paradigm shift just means "change in the way you do things." Or "change in the way you think about things." &nbsp;My computer science words are slipping into conversation! =D