Am I correct in observing that there are no while loops available in expressions? If not, what would be the best way to get around this? Here is the logic I am trying to accomplish
No worries. So first, I am not a seasoned Ignition programmer like many of the whizzes on here (nor do I have a strictly programming background) so just a fair disclaimer.
But referencing the code above, I am trying to accomplish that logic however it would look like in expression script. I mostly just want to get ideas from users. I started getting on a track of using switch and if statements, a memory tag, etc. but a while loop is kind of what's needed and its a little difficult to get around. My ideas so far have just been needlessly complicated.
I am programming a pump component and a corresponding label to reflect three statuses: stopped, running, and faulted.
Guess this context was missing in the above code but the "tag" variable in my code above is a two-state tag with ON state "Running" (1) and OFF state "Stopped" (0.) And then "errortag" is "Faulted" (2.)
I think you've explained it quite well. You're just confused on how tags work. They are constantly re-evaluated based on their schedule, so the expression essentially runs in a while loop.
You can use what Jordan posted above, and it would work.
if({errortag} = True, 2, toFloat({tag}))
I put toFloat as you seemed to have 0.0 and 2.0, but Int would work as well.
@crees Thanks!! Honestly...its possible. Hence my disclaimer above I'll try what you and @JordanCClark suggested and see if it works! If not, I'll be back. Thanks for the help!
It would break the expression whether you use = True or not. Don't waste CPU cycles comparing booleans to True. Perspective needs you to conserve CPU cycles wherever you can.