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

Basic Fantasy RPG - expanded sheet

1501962400
Pat S.
Forum Champion
Sheet Author
I took a few months off from working on the sheet but I'm back at tweaking the sheet. The newest version will have streamlined inventory (it is being minimized down to 4 tabs as I'm consolidating worn and carried tab together) that will soon be autocalc the weight being carried or worn. I have a note field on the sheet for game notes also and that will be viewable across all the tabs at the bottom of the sheet. I have a few other things I'm going to work on also but those are just thoughts at the moment as the encumbrance weight is the main issue focused on right now. Old thread was closed due to age.
1502503914
Pat S.
Forum Champion
Sheet Author
I've tweaked the code and added some additional features. The following has been added to the sheet Inventory now autocalculates all the weight and displays it properly. A game note field has been added to the bottom of the sheet. Work in progress A sheetworker to combine old inventory tabs into one new one. Not working right now but it is being worked on.
1502504642

Edited 1502504665
Pat S.
Forum Champion
Sheet Author
 I'm attempting to combine a repeating fieldset that will not be used (it is removed from the new sheet) to an existing fieldset that is kept when the sheet is updated. Old fieldset is called repeating_inventtab2 and will not exist on the new sheet. Current fieldset  is called repeating_inventtab1 It is not working so I'm trying to understand what am I doing wrong. old sheet worker that was given to me. on("sheet:opened", function() { // Make a list of some attributes on the old sheet that are not on the new sheet, it doesn't have to be all of them. // Just make sure you list at least most of the attrs that are commonly used, like primary stats or whatever. // This will check if any of these attrs exist, if they do you know that this used to be the old sheet. // Make sure to add the attr 'already_transitioned' to the list getAttrs(['list', 'of', 'attrs', 'on', 'the', 'old', 'sheet', 'already_transitioned'], function(attrs) { if(attr.already_transitioned !== '1') { var hasOldData = false; var updates = {}; _.each(attrs, function(value, key) { // loop through the list and see if they exist if(value) { hasOldData = true; } }); if(!hasOldData) { // It's not the old sheet, mark already_transitioned so that we don't ever do the loop again. updates.already_transitioned = '1'; setAttrs(updates); } else { // We know this used to be the old sheet, now we need a list of EVERY attribute you want to copy getAttrs(['list', 'of', 'all', 'attrs', 'on', 'the', 'old', 'sheet'], function(oldAttrs) { // for each attribute, on the left you have the name of the attribute on the new sheet // and on the right you have the name of the attribute on the old sheet updates.newSheetValue1 = oldAttrs.list; updates.newSheetValue2 = oldAttrs.of; updates.newSheetValue3 = oldAttrs.all; updates.already_transitioned = '1'; setAttrs(updates); }); } } }); }); My sheetworker // Transitioning from old sheet to new sheet. on("sheet:opened", function() { // Make sure to add the attr 'already_transitioned' to the list getAttrs(['repeating_inventtab2', 'already_transitioned'], function(attrs) { if(attr.already_transitioned !== '1') { var hasOldData = false; var updates = {}; _.each(attrs, function(value, key) { // loop through the list and see if they exist if(value) { hasOldData = true; } }); if(!hasOldData) { // It's not the old sheet, mark already_transitioned so that we don't ever do the loop again. updates.already_transitioned = '1'; setAttrs(updates); } else { // We know this used to be the old sheet, now we need a list of EVERY attribute you want to copy getAttrs(['repeating_inventtab2'], function(oldAttrs) { // for each attribute, on the left you have the name of the attribute on the new sheet // and on the right you have the name of the attribute on the old sheet updates.repeating_inventtab1 = repeating_inventtab2; updates.already_transitioned = '1'; setAttrs(updates); }); } } }); });
1502531055

Edited 1502614947
Jakob
Sheet Author
API Scripter
Yeah, this is not going to work, because you need to get all the attributes in the section and transfer each of them. The code below should work (up to typos). Of course, you need to fill in the right attribute names in the attrsInSection array. I added a variant of a helper function called fillRepeatingSectionFromData which takes an array of objects and puts of each of the objects in the repeating row with specified name. But you can take it as a blackbox, if you want. var fillRepeatingSectionFromData = (sectionName, dataList) => {   const createdIDs = [];   const setting = dataList.map(o => {       let rowID;       while (!rowID) {         let newID = generateRowID();         if (!createdIDs.includes(newID)) {           rowID = newID;           createdIDs.push(rowID);         }       }       const newAttrs = {};       return Object.keys(o).reduce((m, key) => {         m[`repeating_${sectionName}_${rowID}_${key}`] = o[key];         return m;       }, newAttrs);     })     .reduce((m, o) => Object.assign(m, o), {});   setAttrs(setting); }; on("sheet:opened", function () {   // Make sure to add the attr 'already_transitioned' to the list   getAttrs(['already_transitioned'], function (attrs) {     if (attrs.already_transitioned !== '1') {       getSectionIDs('repeating_inventtab2', idArray => {         // All the attributes in a repeating row that we care about         const attrsInSection = ['itemname', 'itemquantity', 'itemcarriedenc', 'itemdesc'],           // Get an array containing all attribute names for all rows in repeating_inventtab2           allAttrs = idArray.reduce((m, id) => {             return m.concat(attrsInSection.map(attr => `repeating_inventtab2_${id}_${attr}`));           }, []);         getAttrs(allAttrs, v => {           let data = [];           // Construct data from existing attributes           idArray.forEach(id => {             data.push({               itemname: v[`repeating_inventtab2_${id}_itemname`] || '',               itemquantity: v[`repeating_inventtab2_${id}_itemquantity`] || '',               itemwornenc: v[`repeating_inventtab2_${id}_itemcarriedenc`] || '',               itemdesc: v[`repeating_inventtab2_${id}_itemdesc`] || ''             });           });           fillRepeatingSectionFromData('inventtab1', data);           setAttrs({             already_transitioned: '1'           });         });       });     }   }); });
1502532965
Pat S.
Forum Champion
Sheet Author
Thanks Jakob for the info and help. Now I just have to learn this stuff as I have zero coding skills and it looks like a foreign language to me. Names of the old fields  repeating_inventtab2:itemname repeating_inventtab2:itemquantity repeating_inventtab2:itemwornenc repeating_inventtab2:itemdesc to be converted/combined to repeating_inventtab1:itemname repeating_inventtab1:itemquantity repeating_inventtab1:itemwornenc repeating_inventtab1:itemdesc
1502546597

Edited 1502546608
Jakob
Sheet Author
API Scripter
It can be a bit intimidating to start, especially the reduce method may not be very intuitive at first... Anyway, you just need to modify attrsInSection like this: attrsInSection = ['itemname', 'itemquantity', 'itemwornenc', 'itemdesc'],
1502546802
Pat S.
Forum Champion
Sheet Author
I did that but it did not work. I'm just sitting here staring at the code, trying to understand why it is not working.
1502546942
Pat S.
Forum Champion
Sheet Author
This is what I have: // Transitioning from old sheet to new sheet. var fillRepeatingSectionFromData = (sectionName, dataList) => { const createdIDs = []; const setting = dataList.map(o => { let rowID; while (!rowID) { let newID = generateRowID(); if (!createdIDs.includes(newID)) { rowID = newID; createdIDs.push(rowID); } } const newAttrs = {}; return Object.keys(o).reduce((m, key) => { m[`repeating_${sectionName}_${rowID}_${key}`] = o[key]; return m; }, newAttrs); }) .reduce((m, o) => Object.assign(m, o), {}); setAttrs(setting); }; on("sheet:opened", function () { // Make sure to add the attr 'already_transitioned' to the list getAttrs(['already_transitioned'], function (attrs) { if (attr.already_transitioned !== '1') { getSectionIDs('repeating_inventtab2', idArray => { // All the attributes in a repeating row that we care about const attrsInSection = ['itemname', 'itemquantity', 'itemwornenc', 'itemdesc'], // Get an array containing all attribute names for all rows in repeating_inventtab2 allAttrs = idArray.reduce((m, id) => { return m.concat(attrsInSection.map(attr => 'repeating_inventtab2_${id}_${attr}')); }, []); getAttrs(allAttrs, v => { let data = []; // Construct data from existing attributes idArray.forEach(id => { data.push(attrsInSection.reduce((m, attr) => { m[attr] = v['repeating_inventtab2_${id}_${attr}']; return m; }, {})); }); fillRepeatingSectionFromData('inventtab1', data); setAttrs({ already_transitioned: '1' }); }); }); } }); });
1502547094

Edited 1502547158
Jakob
Sheet Author
API Scripter
Pat S. said: I did that but it did not work. I'm just sitting here staring at the code, trying to understand why it is not working. Small typo which I copied from your original code, attr vs attrs, sorry! Fixed it now. (It's in the attrs.already_transitioned !== 1 line).
1502548909

Edited 1502548928
Pat S.
Forum Champion
Sheet Author
Something strange is going on. I updated the sheetworker to reflect the latest. I transmogrified one character into my test game and it worked. I tried with few others and it did not work. 
1502549931

Edited 1502549983
Jakob
Sheet Author
API Scripter
Maybe watching the browser's console for errors will reveal what's wrong. I have a suspicion, though: undefined elements. Fixed the corresponding line (bolded) to make sure stuff is always defined.
1502564342
Pat S.
Forum Champion
Sheet Author
Thank you very much. That did it for everything but one thing. After getting a nap (not feeling well) I came back to start looking at the code and discover something I missed from the beginning. I just realized I have to move data from this line  <div><input type="number" name="attr_ itemcarriedenc "></div> To this line. <div><input type="number" name="attr_ itemwornenc "></div> Everything else works out. I'm assuming that I need to build or try to build a sheetwork that takes the "itemcarriedenc" data and inserts it into "itemwornenc".
1502566652
Gold
Forum Champion
Thanks for your continuing work and efforts on BFRPG.
1502567030
Jakob
Sheet Author
API Scripter
Pat S. said: Everything else works out. I'm assuming that I need to build or try to build a sheetwork that takes the "itemcarriedenc" data and inserts it into "itemwornenc". It depends. Do you only need to do the conversion for items coming from inventtab2, or also for the ones already in inventtab1?
1502576076

Edited 1502576142
Pat S.
Forum Champion
Sheet Author
I'm combining inventtab2 into inventtab1 when I update the sheet. At the moment the current sheet has inventory tab 1 (inventtab1) for items worn and inventory tab 2 (inventtab2) for items carried but in the new sheet it will be inventory tab 1 (inventtab1) for items worn and carried. This means I have to get the data from tab2 to show up into tab1 upon update otherwise there would be the possibility of players losing data on their sheets. The only thing that seems to be different attribute naming is the itemcarriedenc vs the itemwornenc.
1502614988
Jakob
Sheet Author
API Scripter
If I understand correctly, the bolded change should do it.
1502624581

Edited 1502624657
Pat S.
Forum Champion
Sheet Author
Thank you so much. It works. I've commented you into the code to let people know that you helped with the sheetworker. I will probably be posting more to this thread when I run into something beyond my primitive skills.
1505173646
Pat S.
Forum Champion
Sheet Author
To anyone that uses the Basic Fantasy RPG roll20 sheet, the sheet has been updated and is now live. There has been some layout changes along with some of the background mechanics (the equipment now totals up it's weight and a few other things).