How to set an expression tag to not change on false

if true, I change the value, but on false, I don’t want to change the value.
I am not sure how to make it not change though.

Throws an error with “if (condition ,true)” without the false condition.
Throws an error if I put value or if I put it’s own tag.

You can’t do this with an expression. It will have to be done in scripting.

You will need two tags. One to hold the raw value, and one to write the value to if the conditions are met. A tag script can handle the rest.

image
image

Can’t you just set it to itself on the false condition?
image

image

image

I get an error if I set the tag to itself in the false case.

Seems really odd that in an expression tag logical IF, the false case is required.

But yah, in the script, I say if x write y to z
I don’t like that the script has to be on the raw data side rather than the tag that I am working on.
If someone wants to back-trace where it is written from, they have to check all the other spots.

Hmmm… yeah expression tags don’t let you do that. It does work partly but you can’t change the value of the expression tag directly. Jordan’s answer is the correct way.

Why is that odd? Also, what error, I did what @Duffanator suggested and it works just fine.

Couldn’t you also use a derived tag for this?

how do you mean?
don’t those use expression language too?

for clarification
if (rawTag<1000,rawTag,thisTag)
throws an error for me.

if (rawTag<1000,rawTag)
also throws an error for me, and this is the one that seems odd to me that it throws an error
I expected this to work.

Why would you expect the latter to work?
Ignition’s expression language must return a value, by definition. An if with no else is an incomplete statement.

In a derived tag, you could use if({otherTag} < 1000, {value}, {source}) to discard incoming writes based on some other tag.
However, if that’s what your actual expression is, then it really seems like you might just need clamping and/or scaling: Tag Scaling Properties - Ignition User Manual 8.1 - Ignition Documentation

Thanks
I didn’t know I could specify the source in that.

In scripting and other languages I program in, I can typically write
if(condition,true)

Or if condition then x I think expression language and excel are the only ones that I have seen a requirement for a false condition.

I mean that personal previous experiences caused me to think I wouldn’t be required to have a false or else.

Yeah, that’s because Excel formulas are also an expression language. There’s no context or variables; it’s just a stack of operations to execute.

1 Like

I thought I understood this, but I don’t

So source is the path to the raw tag

value is the current value excluding the source?

Derived tags are ‘special’, and set up the read and write expressions with some context (specifically to avoid the problem/limitation of the expression language).

That's a script statement, not an expression. Expressions in every programming language I know must yield a value.

3 Likes

I am an electrical engineer. Forgive me. I took programming for non-believers.

edit
I meant to excuse myself and be honest about not knowing that “Expression Language” was a whole subset of programming languages. I thought it was another programming language unto itself, and as unique as Java, Codesys, or Python. I had thought someone had decided to make Expression Language that certain way.

I am also an electrical engineer. IMNSHO, engineer > programmer, so I expect you can handle this. (:

4 Likes

That’s going to rile some people up… :rofl:

6 Likes

As a programmer: Y’all are wizards :slight_smile:

4 Likes

you cant be both :wink: