Client event scripts does not capture the initial change of a tag

Hello everyone,

I have two screens in vision and I want to be able to toggle between them using an OPT touch button (a boolean tag coming from PLC). I wrote the code below in Client event scripts → Tag Change:

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

So now when I launch the project and use the OPT touch button to switch between screens, the screen does not change with the initial change of the OPT button but when I toggle the button for the 2nd time it works! So basically the code does not capture the initial change.

I also tried the Tag event Scripts on a vision client Tags to toggle between screens, but this works only in the designer mode, I do see the screen changes in the designer mode but not when I launch it.

	if not initialChange:
		if currentValue.value:
			system.nav.swapTo('Bottom')		
		else:
			system.nav.swapTo('Top')

Any idea how this can be fixed?
Thank you!

In your top code block, the primary if statement is only going to execute whenever ‘val’ is True, so it’s essentially blocking the navigation from working half the time.

1 Like

Any idea how can I change this so that it captures the whole time? Thank you very much!

I’ve moved into the Perpective world, so it’s been a bit, but you should be able to create a change change script on the ‘[default]OptTouch’ tag that fires the following code:

if system.nav.getCurrentWindow()== "Top":
	system.nav.swapTo('Bottom')
else:
	system.nav.swapTo('Top')
1 Like

You can try this code which is very similar to your second one, but use it on the client event script and remember to set the script to only trigger when the value changes and ignore quality and timestamp :
Edit: Just use Kyle's script :grinning:

Your second code works all the time because it’s not trying to look if the tag value is True, every tag change fires it. Your first code works half the time because it only changes the screen when the tag is True, so when you toggle your tag from True to False, it does nothing.
But your second code doesn’t work in the client probably because Tag Event Scripts excecute at the Gateway level, so it can’t change a client’s screen.

1 Like

Thank you very much for the great information, Leonardo. I do really appreciate it! :slight_smile:

Thank you very much, Kyle. Appreciate your response! Now it is working the way I excepted it :slight_smile:

1 Like