val= system.tag.readBlocking('[default]OptTouch')[0].value
if val==1 and system.nav.getCurrentWindow()=="Top":
system.nav.swapTo('Bottom')
else val==1 and system.nav.getCurrentWindow()=="Bottom":
system.nav.swapTo('Top')
val= system.tag.readBlocking('[default]OptTouch')[0].value
if val:
if system.nav.getCurrentWindow()== "Top":
system.nav.swapTo('Bottom')
else:
system.nav.swapTo('Top')
val= system.tag.readBlocking('[default]OptTouch')[0].value
if val==1 and system.nav.getCurrentWindow()=="Top":
system.nav.swapTo('Bottom')
elif val==1 and system.nav.getCurrentWindow()=="Bottom":
system.nav.swapTo('Top')
val= system.tag.readBlocking('[default]OptTouch')[0].value
if val==1 and system.nav.getCurrentWindow()=="Top":
system.nav.swapTo('Bottom')
else:
system.nav.swapTo('Top')
# Put your trigger tag ('[default]OptTouch') into Client tag change scripts, then:
# A variable that is a flag (0 or 1) which indicates whether or not the event is due to the initial subscription or not.
# This is useful as you can filter out the event that is the inital subscription,
# preventing a script from running when the values haven't actually changed.
if not initialChange:
# if your tag '[default]OptTouch' has changed to 1 (or True)
if newValue.getValue() == 1:
# Get current window
curWin = system.nav.getCurrentWindow()
# Check if TOP page is opened
if curWin == 'Top':
# Swap to 'Bottom' page
system.nav.swapTo('Bottom') # Must pass the new page's path to the function
# Check if BOTTOM page is opened
elif curWin == 'Bottom':
# Swap to 'Top' page
system.nav.swapTo('Top') # Must pass the new page's path to the function
# else:
# Put here something if you need to.
Short version:
if not initialChange:
# if your tag '[default]OptTouch' has changed to 1 (or True)
if newValue.getValue() == 1:
# Swap to bottom page if current is top, else swap to top page
system.nav.swapTo('Bottom') if system.nav.getCurrentWindow() == 'Top' else system.nav.swapTo('Top')
Solution 1 with a not initialChange condition is probably the best. Most readable and most maintainable. I’m just not a fan of one line ternary operators for function calls in the 3rd solution but its personal preference.