When using a 2 state toggle what is the best way to set up the a script to write the value to a tag? I found two ways of doing this: one through the Event configuration using onActionPreformed script and the other using a change script on props.selected.
Events onActionPreformed script:
def runAction(self, event):
if self.props.selected == 1:
system.tag.write("Test/TestOos",1)
else:
system.tag.write("Test/TestOos",0)
I don't know which of your two solutions would be better but a much better way would be to create a tag binding on the toggle. Point it directly to "Test/TestOos" and make the binding bidirectional. No script needed so it's faster and more efficient.
The two scripts are effectively equivalent (I'll point out that you can rewrite the action as just system.tag.write("Test/TestOos", self.props.selected)), but the better question is - why use a script at all? A bidirectional binding on selected will mean that your toggle always reflects the value of the tag, and writes back to the tag whenever the button is pressed.