Swapping Screens based on a tag from PLC

Hello everyone,

I want to be able to change the screen based on a boolean tag (an OPT touch button) from PLC. I have two screens (Top/Bottom) and before changing the screen first I want to know which screen is open.

So for example when the Top screen is open and I touch the Opt touch button I want to change the screen to the Bottom screen and vice versa.

I wrote a tag change client event script but it did not work:

val= system.tag.readBlocking('[default]OptTouch').value
if val==1 and system.nav.getCurrentWindow()="Top":
else val==1 and system.nav.getCurrentWindow()="Bottom":

I do really appreciate any information from you guys.

Thank you!

Tags under [default] are gateway tags that exist in the gateway scope. They cannot directly manipulate the GUI of clients. When you write that, that tag is executing that code on the server itself which is not a client and so you won’t see anything happen in any client.

What you need to do is in your tag change do a sendMessage to the client scope, and in the client events, set a message handler, and there you can do your screen swaps.

Mind you, unless you parse it to only send the message to a specific user or clientId, this will be happening on all clients them. So without this specification, if the tag changes, your message is sent to all clients, at which point every single client’s windows will change based on your logic. If this is what you want that’s simpler. Otherwise you might want a user='operator' keyword argument in your sendMessage from the gateway to the client.


Alternatively, you could put the tag change in the Client Tag Change Scripts event instead of the gateway tag change script events. But again, this means every client will be subject to the logic without further parsing based on username or similar. Not to mention depending on the speed of your tag changes and your scan class its easy to get a miss.

1 Like

shouldnt this be == ?

1 Like

Also its not a good idea to store the state of a client in a tag. because you can have mutple clients reading the same tag.
Tho i guess if you only have one plc button it will be linked to just one screen so yeah not to bad i guess

1 Like

No, with "==" I still get errors, and I feel like "=" is correct but I may be wrong.

im sure you need 2 ‘==’ there its in an if


Good! So the error is coming from another thing probably.

Where is this change script? Under gatweay events? Under value change of the tag itself? Under client events?

1 Like

It is under client events → Tag Change → Client Tag change script

1 Like

ah you need elif instead of else


For read blocking you have to provide a list of tag paths, and then you get a list of values back. So
system.tag.readBlocking('[default]OptTouch').value will not work.

system.tag.read('[default]OptTouch').value I think would work.

1 Like

Thank you! My bad. The error is now gone; however, I cannot toggle the screen based on that tag.

Actually you just need an else with no comparisons. There are only two states, no need for the 2nd set of conditions.


I have only two options:




And I am using Ingnition 8.1
I change it to read but I am still not able to toggle between screens.

blocking returns an array so you will have to add in [0]


is a vision function only


1 Like

I still have the error, it is stating that “mismatched input val expecting a colon”

You are correct! I am using Vision

ah mb xd

you forgot the ':' after if/ else?

1 Like