Is it Possible to Sync two Switch Components

I have a multi-page app that is achieved by hiding/showing different screen arrangements.

A couple of pages have settings switches that need to synchronise. i.e. if I switch one switch, the other also switches, and visa versa.

Can someone help me understand, conceptually, how I can synchronise these two swicthes without creating the extra flyback processing? I think using the ".Changed" function of the switch, the code will fly back one extra step unnecessarily eg:

  1. Switch 1 on, switch 2 on.
  2. Manually change switch 1 to off.
  3. Through the ".Changed" function of switch 1, we programmatically turn switch 2 off, but becasue switch 2 turns off, this ".Changed" then prompts a return to switch 1, but seeing as switch 1 is already set to off there is no "Change" and the execution stops.

Is this third flyback necessary or is it really a non-problem?


I don't think it's a huge thing, but just wondering if there's a better way of approaching it.

blocks (23)

Switch.aia (2.0 KB)

Thanks. I'm getting a server error while loading the aia. I'll have to wait a bit until it sorts itself out.

Is working now.

I don't really understand the "Any Component" "Any Switch". What is this component?

Well, the Any Component and Any Switch blocks can be found in the component tree in the Blocks editor.

  1. Click on the + icon next to Any Component.

image

  1. Click on Any Switch.

image

There you can find the blocks.

These blocks are generic blocks. You do not necessarily need to know what components they are setting/getting, and they are useful for loops like "for each item in list". You can find more in the documentation.

http://ai2.appinventor.mit.edu/reference/other/any-component-blocks.html

1 Like

Thank you. More reading for me I think.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.