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

Creating a pullable list

I'm trying to figure out how to have a sheet pull a static number from a list (XP to level) if I assign it a trigger (Skill Level). Can HTML do something like, If level=6 then XP to level = 2000. Or, If level=7 then XP to level = 3500
1551215937

Edited 1551216238
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I'd recommend a sheetworker for this. Something like (untested): on('change:blacksmithing',(event)=>{     const levelUp = [0,200,500,700,1000,1500,2000,3500],//The lookup table for xp scaling         setObj = {},//Our object to use to set attributes         skillLevel = Math.min(event.newValue*1||1,7),//turn the value into a number, and make sure that it limits it's value to the scale supported by the lookup table         skillXPName = `${event.sourceAttribute}_xp_max`;//Converts the name of the skill to the name of the skill's xp max attribute     setObj[skillXPName] = levelUp[skillLevel];//Lookup the skill level in the table     setAttrs(setObj,{silent:true});//Set the attribute }); Note that I've made assumptions about your sheet's attribute naming scheme and obviously about the xp progression. You'll need to edit this as needed for your rules system. You'll also need to stick this inside a <script> element. All sheetworkers go in the same <script> element.
I've never used sheetworkers before. I'm not even sure how they function. Do I add the dialogue box to the CSS sheet and then add a <script> element to the HTML to modify/interact with it? I feel as if this may be a bit complex for my current level of knowledge.
1551237116

Edited 1551240087
GiGs
Pro
Sheet Author
API Scripter
sheet workers go in the html sheet. At the bottom of your html, add the following <script type="text/worker"> </script> That is a script block. All sheet workers you create, like Scott's above, go in that script block: between those two script statements. The approach I'd use is below. This single worker will work for all your skills, if they are named appropriately. const skills = ['blacksmithing','fencing','alertness','etc']; skills.forEach(skill => { on(`change:${skill}`, function(){ getAttrs(['skill'], values => { const levelUp = [0,200,500,700,1000,1500,2000,3500]; const value = values[skill]*1||0; const level = levelUp[Math.min(value, levelUp.length -1)]; setAttrs({ [`${skill}_xp`]: level },{silent:true}); }); }); }); In this version, you need make three changes. First, edit the following lines: const skills = ['blacksmithing', 'fencing', 'alertness']; Add an extra entry for each skill, after a comma and enclosed in quotes like above. So if you also had carpentry and jeweller skills, you'd change that to const skills = ['blacksmithing', 'fencing', 'alertness', 'carpentry', 'jeweller']; You can list the skills in any order. Also you'd ned to change this: const levelUp = [0,200,500,700,1000,1500,2000,3500]; to whatever your Level -> XP sequence is.  And finally in this section [`${skill}_xp`]: levelUp[level] I've assumed your skill levels are named like, "blacksmithing" and the XP box is named "blacksmithing_xp". If so just change the '_xp' in the above to whatever you use. If you use a different naming sequence, you might need to make tweaks. If for instance, your names are 'blacksmithing_level' and 'blackmsmith_xp' its a touch trickier, but not much. Let us know what naming scheme you use.
1551237186

Edited 1551237241
GiGs
Pro
Sheet Author
API Scripter
Scott C. said: I'd recommend a sheetworker for this. Something like (untested): on('change:blacksmithing',(event)=>{     const levelUp = [0,200,500,700,1000,1500,2000,3500],//The lookup table for xp scaling         setObj = {},//Our object to use to set attributes         skillLevel = Math.min(event.newValue*1||1,7),//turn the value into a number, and make sure that it limits it's value to the scale supported by the lookup table         skillXPName = `${event.sourceAttribute}_xp_max`;//Converts the name of the skill to the name of the skill's xp max attribute     setObj[skillXPName] = levelUp[skillLevel];//Lookup the skill level in the table     setAttrs(setObj,{silent:true});//Set the attribute }); Note that I've made assumptions about your sheet's attribute naming scheme and obviously about the xp progression. You'll need to edit this as needed for your rules system. You'll also need to stick this inside a <script> element. All sheetworkers go in the same <script> element. Scott, shouldnt this bit  setObj[skillXPName] = levelUp[skillLevel]; be setObj[skillXPName] = levelUp[skillLevel -1]; ?
1551238501

Edited 1551238698
Alright. It's making a lot more sense now that you've helped break it down GiGs. The only field that I didn't understand is: [`${skill}_xp`]: levelUp[level] As for naming sequence, I haven't chosen a hard set one yet. So I will most likely use and build off of the examples in which you have provided. Am I correct in assuming that this script is like a collection of containers for storing values (Like const skills, and const levelup) If that's the case, how would I go about pulling things from the containers so that I can apply them? Is it possible through an HTML input command? Or maybe I am just overthinking this. Or underthinking haha.
1551239018
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
GiGs said: Scott C. said: I'd recommend a sheetworker for this. Something like (untested): on('change:blacksmithing',(event)=>{     const levelUp = [0,200,500,700,1000,1500,2000,3500],//The lookup table for xp scaling         setObj = {},//Our object to use to set attributes         skillLevel = Math.min(event.newValue*1||1,7),//turn the value into a number, and make sure that it limits it's value to the scale supported by the lookup table         skillXPName = `${event.sourceAttribute}_xp_max`;//Converts the name of the skill to the name of the skill's xp max attribute     setObj[skillXPName] = levelUp[skillLevel];//Lookup the skill level in the table     setAttrs(setObj,{silent:true});//Set the attribute }); Note that I've made assumptions about your sheet's attribute naming scheme and obviously about the xp progression. You'll need to edit this as needed for your rules system. You'll also need to stick this inside a <script> element. All sheetworkers go in the same <script> element. Scott, shouldnt this bit  setObj[skillXPName] = levelUp[skillLevel]; be setObj[skillXPName] = levelUp[skillLevel -1]; ? Nope, cause at the 0 position I put 0 instead of an actual value.
1551239542
GiGs
Pro
Sheet Author
API Scripter
Scott C. said: Nope, cause at the 0 position I put 0 instead of an actual value. Ahh, clever :) I should have spotted that.
1551240038
GiGs
Pro
Sheet Author
API Scripter
Danny Martini said: Alright. It's making a lot more sense now that you've helped break it down GiGs. The only field that I didn't understand is: [`${skill}_xp`]: levelUp[level] As for naming sequence, I haven't chosen a hard set one yet. So I will most likely use and build off of the examples in which you have provided. Am I correct in assuming that this script is like a collection of containers for storing values (Like const skills, and const levelup) If that's the case, how would I go about pulling things from the containers so that I can apply them? Is it possible through an HTML input command? Or maybe I am just overthinking this. Or underthinking haha. You place this script in the sheet, and it does the work for you. Whenever you change a skill rank, it will automatically update the XP for that skill. This assumes you have paired inputs like: <input name="attr_blacksmithing" type="number" value="0" /> <input name="attr_blacksmithing_xp_max" type="number" value="0" readonly/> The readonly in the second one is to ensure that players cant alter the value. Scott's suggestion of using _xp_max  as the ending name is better than mine of simply using _xp , since you do actually have a current XP box for the skills too. const declares what follows as a constant , a variable that cannot change. It is a way of storing data in scripts, that the script can draw on. skills  and levelUp  are arrays: a collection of items (skill names or experience totals in these cases). Scripts can manipulate arrays in a variety of ways.  The script is more than a collection of objects - it also does things with those objects (as in this case: getting the skill level, and looking in the levelUp array to find the corresponding XP total, then printing it out to the character sheet). 
1551241063
GiGs
Pro
Sheet Author
API Scripter
I hope Scott doesnt mind, but here's a version of his script tweaked to cope with any number of skills: const skills = ['blacksmithing', 'fencing', 'alertness']; on(skills.reduce((changes,skill) => changes + `change:${skill} `,''),(event)=>{     const levelUp = [0,200,500,700,1000,1500,2000,3500],//The lookup table for xp scaling         setObj = {},//Our object to use to set attributes         skillLevel = Math.min(event.newValue*1||1, levelUp.length-1),//turn the value into a number, and make sure that it limits it's value to the scale supported by the lookup table         skillXPName = `${event.sourceAttribute}_xp_max`;//Converts the name of the skill to the name of the skill's xp max attribute     setObj[skillXPName] = levelUp[skillLevel];//Lookup the skill level in the table     setAttrs(setObj,{silent:true});//Set the attribute }); Assuming you are using _xp_max as the name ender, all you need to change is the skills  array and the levelup  array. Either script will do the job.
Alright. I entered the modified script of Scotts and it works perfectly on the sheet. However, i'm still a little baffled on how it just seems to magically work. How exactly is my Blacksmithing entry pulling data from the script. I'm guessing it's using the attribute_blacksmithing as a link to the scripts const skills? As for the const levelup link... uh... I don't know haha. I appreciate you guys being awesome in helping me get my sheet into better working condition. I've learned a lot from the community just today.
1551242012
GiGs
Pro
Sheet Author
API Scripter
Danny Martini said: Alright. I entered the modified script of Scotts and it works perfectly on the sheet. However, i'm still a little baffled on how it just seems to magically work. How exactly is my Blacksmithing entry pulling data from the script.  You know when you visit a page on the web, and click a button and something happens? Or select an entry from a dropdown list, and the something happens? Roll20 character sheets are basically doing the same thing. In the case of roll20, you have a programming engine sitting there, watching the sheet, waiting for changes. You know the first line of Scott's original script: on('change:blacksmithing',(event)=>{ That tells the programming engine: "when the blacksmithing attribute changes, jump into action". And so when you change the blacksmithing attribute, it is detected, and this script runs.
1551242585

Edited 1551243042
GiGs
Pro
Sheet Author
API Scripter
The actual specifics of how it runs are in this line: skillLevel = Math.min(event.newValue*1||1, levelUp.length-1), This is a bit complicated, but the key part is this: event.newValue This says: the attribute that just changed, get it's value. So if you just change the level to 3, that becomes 3. Ignoring the rest of that line, that means we now have skillLevel = 3 We have a variable called skillLevel, and it equals 3. Then we have levelUp[skillLevel] Which therefore becomes levelUp[3] This tells us to look at item 3 in the levelUp array. Now just to complicate things, the first item in an array is always 0,&nbsp; so we have 0, 1, 2, 3: item 3 is the 4th item. Since the levelUp array is levelUp = [0,200,500,700,1000,1500,2000,3500], the 4th item is 700, so we have grabbed the XP value of 700. The rest of the script is simply sending that number to the correct attribute. If you want to learn more, there's a bit of a guide here: <a href="https://wiki.roll20.net/Sheetworker_examples_for_Non-programmers" rel="nofollow">https://wiki.roll20.net/Sheetworker_examples_for_Non-programmers</a>
1551242805
vÍnce
Pro
Sheet Author
I love following your posts GiGs.&nbsp; Awesome explanations. Thank you.
1551242984
GiGs
Pro
Sheet Author
API Scripter
Aww, shucks. Thank you!