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

API sheetworkers return wrong defaults when multiple fields reference same attribute

1535041030
Lucian
Pro
API Scripter
Create a new game with the following custom sheet: <input type="number" name="attr_source_value" value="10"> <input type="hidden" name="attr_source_value"> <input type="number" name="attr_output">   <script type="text/worker">       function sheetOpened() {         getAttrs(['source_value', 'output'], (vals) => {             if (vals.output === '' || vals.output === undefined) {                 log(JSON.stringify(vals));                 log(vals.source_value);                 const output = vals.source_value / 2;                 log(output);                 setAttrs({output});             }         });     }       on('change:sheet_opened', sheetOpened);     on('sheet:opened', sheetOpened); </script> and the following API script: on('chat:message', (msg) => {    if(msg.content === '!makeChar') {        const char = createObj('character', { name: 'test' });        const attr = createObj('attribute', { name: 'sheet_opened', characterid: char.id});        attr.setWithWorker({current: 1});    } }); Open the game, create a new character, go to the character sheet Observe that the source value is 10, and the calculated field is set to 5 - half the source value. This is as expected. Now run !makeChar from the chat window Open the resulting character called "test" and go to the character sheet. Observe that while the source value is still 10, the calculated field is set to 0 - because the API sheetworkers have incorrectly returned an empty value for the source field. I noticed this because of issues with Shaped startup, which is why I've created a testcase that tests behaviour immediately after creating a new character. I'm not sure if this also happens in every case where there are two fields for the same value, or whether it's only before the character has actually been opened for the first time. I've already spent too long nailing this one down so I'll leave that you for you guys to work out - but at least you have some reliable reproduction steps which is more than I usually give you ;-)
1535041376
Lucian
Pro
API Scripter
Looks like this may be a regression. See here: <a href="https://app.roll20.net/forum/post/4618223/api-sheetworkers-dont-find-default-values-for-attributes-displayed-in-multiple-fields" rel="nofollow">https://app.roll20.net/forum/post/4618223/api-sheetworkers-dont-find-default-values-for-attributes-displayed-in-multiple-fields</a>
1535042030
Lucian
Pro
API Scripter
FWIW, the lexical order of the fields doesn't seem to matter as much as the types - seems like hidden fields are used in preference to normal inputs. I think whatever happens, it would be good to have the behaviour in these cases clearly defined so sheet authors know what they need to do. In an ideal world, I'd expect the system to take the first non-empty value as the default for the attribute - which seems to be what the client version of the code does.
Hey Lucian, We're going to go ahead a created a ticket for this so the Dev team can investigate further!