I have 2 tags High Force 1 and OffsetForce 1. I have another tag (Time passed) that's keeping track of minutes since a button click. After 3 mins, I check whether HF 1 is within +-5% of OF 1. If it's not within that range I want to change the value of a boolean tag to true.
So in Time passed, I wrote this change script but my boolean tag never changes to true even though HF 1 is outside the range:
You're not checking the actual value of the tags for highF or offsetF. Plus you should really read and write all of the tags at the same time.
readBlocking() returns a list of QualifiedValues, you are just referenceing the first QV, but not the actual value of that tag, so if-else clause is not evaluated the way you think that it should be.
Because this is in a Tag Value Changed Script, we want the script to execute a quickly as possible, so if the current value isn't within range don't do anything. Which is why I put everything within the first check.
You want the script to write False if the highF is not within the limits.
That expression is short hand for the following:
lowLimit < highF.value and highF.value < highLimit
This will evaluate True if highF is within the limits, so we invert it with a not , however, we need to insure that we evaluate the expression prior to inversion so we enclose it in parenthesis.
not (lowLimit < highF.value < highLimit)
Python will evalueate the expression and return true or false prior to the call to writeBlocking()
Consider, for the sake of you and everyone who comes after you, separating boolean expressions like that into standalone variables to make their logic and purpose more clear:
I thought so, but then I did some test runs and I noticed that once Alert becomes true it doesn't change to false even when I change highF to within the range
I'm really not sure, the only thing that I can suggest is to put some logging into the script to verify the code is executing the way you think it is. Assuming that the code executes, if the highF value is within the range, then False should be written to the tag.