Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

What is tweenjs_count and why is it affecting my props?

Community Beginner ,
Feb 13, 2020 Feb 13, 2020

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
386
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 13, 2020 Feb 13, 2020

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;
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 13, 2020 Feb 13, 2020
LATEST

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.

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