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:
Copy link to clipboard
Copied
Your code was a bit difficult to follow because you've made some odd coding choices.
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;
}
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.