Highlighted

What is tweenjs_count and why is it affecting my props?

Community Beginner ,
Feb 13, 2020

Copy link to clipboard

Copied

Please see my code excerpt below. For some reason when I run my project it seems to add a prop 'tweenjs_count' and it's throwing off the function below. Any insight would be massively appreciated. 

 

mode_ratios: {
        normal: 1,
        unbalance: 0,
        misalignment: 0,
        looseness: 0,
        bearing: 0, 
        resonance: 0,
}

function calc_peak_height(peak_name){
    let height;
    height = 0;
    for(let mode in props.mode_ratios){
        if(Boolean(props.peak_scaleY[mode][peak_name])){
            height += props.peak_scaleY[mode][peak_name] * props.mode_ratios[mode]
            };
        }
    return height;
};

 

 The error message I receive seems to allude to the fact that there are no corresponding 'peak_names' for the prop 'tweenjs_count'. 

 

See screengrab below: 

 

Capture.PNG

 
TOPICS
Code, Error, Other, Performance

Views

150

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

What is tweenjs_count and why is it affecting my props?

Community Beginner ,
Feb 13, 2020

Copy link to clipboard

Copied

Please see my code excerpt below. For some reason when I run my project it seems to add a prop 'tweenjs_count' and it's throwing off the function below. Any insight would be massively appreciated. 

 

mode_ratios: {
        normal: 1,
        unbalance: 0,
        misalignment: 0,
        looseness: 0,
        bearing: 0, 
        resonance: 0,
}

function calc_peak_height(peak_name){
    let height;
    height = 0;
    for(let mode in props.mode_ratios){
        if(Boolean(props.peak_scaleY[mode][peak_name])){
            height += props.peak_scaleY[mode][peak_name] * props.mode_ratios[mode]
            };
        }
    return height;
};

 

 The error message I receive seems to allude to the fact that there are no corresponding 'peak_names' for the prop 'tweenjs_count'. 

 

See screengrab below: 

 

Capture.PNG

 
TOPICS
Code, Error, Other, Performance

Views

151

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 13, 2020 0
Adobe Community Professional ,
Feb 13, 2020

Copy link to clipboard

Copied

Your code was a bit difficult to follow because you've made some odd coding choices.

  • You've used "let" instead of "var" for no apparent reason.
  • You're creating and assigning "height" in separate lines instead of a single statement.
  • The explicit cast to Boolean in the if check is redundant.
  • You don't put semicolons after curly braces in JavaScript (except when declaring an object literal).
  • The height increment line is missing its end semicolon.

That being said, you haven't provided enough context to make a solid diagnosis, but I'm guessing that the for...in loop is also iterating over inherited values. This might fix your issue:

function calc_peak_height(peak_name) {
	var height = 0;
	for (var mode in props.mode_ratios) {
		if (props.mode_ratios.hasOwnProperty(mode) && props.peak_scaleY[mode][peak_name]) {
			height += props.peak_scaleY[mode][peak_name] * props.mode_ratios[mode];
		}
	}
    return height;
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 13, 2020 1
Community Beginner ,
Feb 13, 2020

Copy link to clipboard

Copied

Hi Clay, Thanks for answering and all the feedback, I greatly appreciate it. 

That was silly with the height wasn't it, I'm working against a clock so missed that! 

Unfortunately, your solution has not worked and I get the same error. The only way I've been able to remedy it is to place a sort of 'dummy' prop called 'tweenjs_count' and set it to zero. This isn't really a very neat solution though 😞

Thanks again for having a try.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 13, 2020 0