Increase a tag value by scripting

	c=currentValue.value
	p=previousValue.value
	if not initialChange:
		if p!=c:				
			if c==0:
				BDindex=system.tag.readAsync("[Malu OPC tags]Rubber_Extruder/BDIndex/BDIndex").value
				system.tag.writeAsync("[Malu OPC tags]Rubber_Extruder/BDIndex/BDIndex",BDindex+1)

How to modify the code to make it works, thanks a lot.

try

c == False

or convert c to integer

int(c) == 0

and… try to write Gateway Event Script Timer for that if You want it will decrease constantly while Trigger is False

You need to use a readBlocking if you need the value in the next line

3 Likes

@deon.korb is right, writeAsync doesn’t return the value.
You also don’t need to check for previous != current since it’s a value changed script.

if not initialChange and currentValue.value:
	idx = system.tag.readBlocking(["[Malu OPC tags]Rubber_Extruder/BDIndex/BDIndex"])[0].value
	system.tag.writeAsync(["[Malu OPC tags]Rubber_Extruder/BDIndex/BDIndex"], idx+1)
1 Like

This is out of order. When initialChange is true, previousValue is null. So the preceding line blows up trying to look up .value on a None. Move the assignment to p to after that check.

1 Like