Tag Reading/Writing

Hey guys! I’m trying to get a script to work in a perspective project that would allow me to constantly read a value from an OPC Tag and write it to another OPC Tag while the condition of a memory tag is in a certain condition.

If you look at the image below, while the dropdown selection box is in Automatic, read the value from Power Constraint From REE (ACS) (MW) and write it to Power Constraint Applied (MW). Then I need it to loop so that it recognizes any changes from the first tag and automatically writes that new value to the second tag.

Here is my current code that doesn’t work that I have in a valueChanged script on Operating Mode:

while ("[.]Operating_Mode" == "Automatic") :
	system.tag.writeBlocking("[.]Power_Constraint", "[.]REE_Power_Constraint")
	if ("[.]Operating_Mode" != "Automatic") :

Any Ideas?

Also, I am able to make this work with the Apply button beside the dropdown, but I need to to perpetually read and write the first tag to the second tag the entire time that the dropdown is in Automatic.

Just put a tag change script on tag “A” that writes to tag “B”, but only if a read on tag “C” is true.

You need to read the value.

readPaths = ['[.]Operating_Mode','[.]REE_Constraint']
writePaths = ['[.]Power_Contraint']

qValues = system.tag.readBlocking(readPaths)

if qValues[0].value == 'Automatic':

By definition, tag valueChange scripts only occur once per value change. Writing a script which potentially executes infinitely is not going to end well.

If for some reason I had to do this in script then I would place this script in a Gateway Timer Script.

A better idea, I think, is to use an expression tag with a Driven Tag Group, where the Operating Mode is the driver for the group.


Here’s the valueChanged script I put on tag “A”:


Does anything stand out to you that may be wrong? Still not working.

system.tag.writeBlocking requires a path and a value. You’ve given it two paths. Read @lrose’s code again.

Tip: Post code, not pictures of code. (Use the </> button to preserve indentation and syntax highlighting.) That we we can copy it into our answers and edit it.

I put @lrose’s code in there but that didn’t work either…

I found the issue guys! I had a an error on a piece of unrelated script that was also placed in the valueChange script area. I hadn’t done any testing on that piece yet, never would have guessed that if would have stopped all script execution if that piece errored out.

Good!, but please don’t post pictures of code!

I noticed that nobody else posts snippets of their stuff when they have questions, why is that? What is the correct way to do that? Thanks for helping me out!

We do post snippets, but as formatted text. As @Transistor described. A screenshot is not a snippet in most of our minds.


I would recommend posting a screenshot if you need to show context to the code such as below.

I would then also post the code as formatted text (<>) so that anyone trying to reproduce the problem or trying to use the code in their answer doesn’t have to type it all out again. Make it easy for those you’re asking to help you!


Sounds good guys, thanks for the info. Will do!