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

Sheetworker, need someone to check my work because its broke

1539709313
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Trying to avoid an autocalc so I need this to work. // Greater Effects on('sheet:opened change:repeating_rituals:greatereffects', function (e) { updateGreaterEffectsMultiplier(); }); function updateGreaterEffectsMultiplier(callback) { console.log('********* updateGreaterEffectsMultiplier ***********'); callback = callback || noop; TAS.repeating('rituals') .fields('greatereffects', 'greatereffectsmultiplier') .each(function(r){ var effects = (r.greatereffects); var multi = (( 2 * effects) + 1 ); setAttrs({ repeating_rituals:greatereffectsmultiplier: multi; }); }); }
1539715179
Jakob
Sheet Author
API Scripter
You have a syntax error
1539715432
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
I knew that... Captain Obvious LOL
1539718060
Jakob
Sheet Author
API Scripter
Scott S. said: I knew that... Captain Obvious LOL If you knew that, why do you ask? If you enter your code in e.g. the Closure Compiler that I linked, it will show you that there are errors in line 14, i.e. : repeating_rituals:greatereffectsmultiplier: multi;
1539718871
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
The compiler is only telling me to add more commas and such. Its not actually helping fix the script. I was looking for a little more than "use this compiler"
1539719539
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
This is the result: It still doesn't update the greater effects multiplier. // Greater Effects on('sheet:opened change:repeating_rituals:greatereffects', function (e) { updateGreaterEffectsMultiplier(); }); function updateGreaterEffectsMultiplier(callback) { console.log('********* updateGreaterEffectsMultiplier ***********'); callback = callback || noop; TAS.repeating('rituals') .fields('greatereffects', 'greatereffectsmultiplier') .each(function(r){ var effects = (r.greatereffects); var multi = (( 2 * effects) + 1 ); setAttrs({ r,greatereffectsmultiplier: multi }); },)}
1539739715

Edited 1539739823
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The reason that Jakob sent you to the closure compiler is because it is the best way to find simple code problems like missed brackets and what not. However, your problem is one that wouldn't be caught since it is technically valid syntax. // Greater Effects on('sheet:opened change:repeating_rituals:greatereffects', function (e) { updateGreaterEffectsMultiplier(); }); function updateGreaterEffectsMultiplier(callback) { console.log('********* updateGreaterEffectsMultiplier ***********'); callback = callback || noop; TAS.repeating('rituals')//You should really end every declaration with a semi-colon or a comma depending on the line .fields('greatereffects', 'greatereffectsmultiplier')         .each(function(r){ var effects = (r.greatereffects); //This doesn't really serve a purpose, if you still want to do it this way, then you can combine these into a single var declaration var multi = (( 2 * effects) + 1 );     setAttrs({     r,greatereffectsmultiplier: multi//You have a comma after r instead of period, and you can't dynamically create a key this way anyways, you have to use template literals }); },)}//I'm not as familiar with TAS syntax, but is this comma supposed to be here? Those comments result in this minorly changed code: // Greater Effects on('sheet:opened change:repeating_rituals:greatereffects', function (e) { updateGreaterEffectsMultiplier(); }); function updateGreaterEffectsMultiplier(callback) { console.log('********* updateGreaterEffectsMultiplier ***********'); callback = callback || noop; TAS.repeating('rituals') .fields('greatereffects', 'greatereffectsmultiplier')         .each(function(r){ var multi = (( 2 * r.greatereffects) + 1 );         setAttrs({          `${r.greatereffectsmultiplier}`: multi             });         }) },
1539740267

Edited 1539740400
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Thank you, see now I will learn, and get better at this. The "r,greater...." that's the result of the compiler. I felt that it wasn't right but alas..I am not an expert. Thanks so very much!
1539756194

Edited 1539756382
Jakob
Sheet Author
API Scripter
And to make it actually compile: // Greater Effects on('sheet:opened change:repeating_rituals:greatereffects', function (e) { updateGreaterEffectsMultiplier(); }); function updateGreaterEffectsMultiplier(callback) { console.log('********* updateGreaterEffectsMultiplier ***********'); callback = callback || noop; TAS.repeating('rituals') .fields('greatereffects', 'greatereffectsmultiplier') .each(function(r){ var multi = (( 2 * r.greatereffects) + 1 ); setAttrs({ [`${r.greatereffectsmultiplier}`]: multi }); }); } (note the square brackets around the property name in the object literal). By the way, the following is equivalent to your lines 2-4, and you should probably use it instead to simplify things: on('sheet:opened change:repeating_rituals:greatereffects', updateGreaterEffectsMultiplier); Also, why do you have the callback parameter? It's never called anywhere.
1539780936
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Ah, thanks Jakob, I don't use that object syntax myself, so couldn't remember.
1539781988
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Jacob said, on('sheet:opened change:repeating_rituals:greatereffects', updateGreaterEffectsMultiplier); In my defense that's how nearly all of my sheetworkers on my adopted project are written. I use them as an example. More importantly, I really appreciate all the help I get from the community. I am learning JS as I go. As well as CSS and HTML, although I am far more advanced with the latter. Again all help an suggestions are greatly appreciated.
1539782322
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Callback is called for elsewhere in the sheetworkers. Although not sure why yet...again still learning.
1539783994
Jakob
Sheet Author
API Scripter
Scott S. said: Jacob said, on('sheet:opened change:repeating_rituals:greatereffects', updateGreaterEffectsMultiplier); In my defense that's how nearly all of my sheetworkers on my adopted project are written. I use them as an example. More importantly, I really appreciate all the help I get from the community. I am learning JS as I go. As well as CSS and HTML, although I am far more advanced with the latter. Basically, what your previous code is doing is that it defines an anonymous function, and the only thing this function does is call the updateGreaterEffectsMultiplier function. In my variant, the updateGreaterEffectsMultiplier function is called directly.* * There is a miniscule difference in that your anonymous function takes an "event" parameter. However, since this parameter is never used anywhere, and since updateGreater EffectsMultiplier takes no parameters, it comes down to the same thing due to how Javascript operates in this regard: if you pass more parameters to a function than it knows how to handle, it will just ignore the extra parameters.
1539787498
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
I am still having an issue with it not updating the multiplier. I am double checking everything now.