Scaling with Expression

I’ve been trying to write an expression to change the value of a tag but i either get an error or the return value comes out empty. I know I can use the “Scale Mode” under “Numeric Properties” and scale the value that way, but I would really like to know how to do it with an expression since I believe it can be faster. I’ve attached a screen picture of how it looks now and also another one of the expression I’ve tried to write and what it returns, any help would be greatly appreciated.

1.) first image of how the tag is configured

2.) second image of how I configure the tag with the expression and the error it generates

3.) third image of the code I wrote to tried and change the return value
image

Should be toFloat instead of tofloat. They are case sensitive.

It looks like the issue is that you’re referencing the tag inside its own definition. Each tag can only store a single value, so any scaling would have to be done when reading from or writing to that tag, not in the tag expression itself. What you’re trying to do there isn’t possible with a single expression tag, since it has to reference some saved value before it can scale that value.

Are you running into performance issues using the “Scale Mode”? If not, I don’t think you’d benefit much from a different approach, and if so, then I think you might have bigger problems lol. If you’re trying to speed up your tags, I’d first look into changing the update speed in the tag group.

2 Likes

Thank you Brandon, now it makes sense.

1 Like

Another thing that might help is this:
Whenever you see an Error_ExpressionEval, open the tag editor and click on Details -> Diagnostics to see the error message it’s giving you. That will give you more information about the error and help you find the underlying issue.

In this example, my tag is referencing itself, so here’s how it tries to resolve it:

  1. Tag value is null
  2. Evaluate expression
  3. Evaluate multiplication
  4. Evaluate left operand
  5. Left operand references tag value
  6. Tag value is still null
  7. Throw Expression left operand is null error