Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using variable 'limit_max' causes error: Unexpected token '.' #4

Open
idbrii opened this issue Jul 10, 2020 · 1 comment
Open

Using variable 'limit_max' causes error: Unexpected token '.' #4

idbrii opened this issue Jul 10, 2020 · 1 comment

Comments

@idbrii
Copy link

idbrii commented Jul 10, 2020

The automatic Math. prefix doesn't search for whole words so if your javascript code has any tokens that contain names in Math, they fail with a confusing error message:

// Error: Unexpected token '.'
function clamp(num, limit_min, limit_max) {
  return num <= limit_min ? limit_min : num >= limit_max ? limit_max : num;
}

// No error after renaming to avoid 'max' and 'min'
function clamp(num, limit_in, limit_ax) {
  return num <= limit_in ? limit_in : num >= limit_ax ? limit_ax : num;
}
@idbrii
Copy link
Author

idbrii commented Jul 10, 2020

It's not really important, but for context, this is the full javascript I was using:

const c4 = (2 * PI) / 3;

var a = x === 0
  ? 0
  : x === 1
  ? 1
  : -pow(2, 10 * x - 10) * sin((x * 10 - 10.75) * c4);

// function clamp(num, limit_min, limit_max) {
//   return num <= limit_min ? limit_min : num >= limit_max ? limit_max : num;
// }

function clamp(num, limit_in, limit_ax) {
  return num <= limit_in ? limit_in : num >= limit_ax ? limit_ax : num;
}

y = 0.01 + 0.4*x + 1 * a
y = clamp(y,0,1.5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant