Ok, so I know how to do what I’m thinking of in a bull-in-a-china-shop kind of way. That is, I can plow through it with a bunch of code, but I’m almost certain there has to be a more elegant way.
If there is, I’m not sure how to phrase it.
This scenario isn’t exactly what I’m hoping to create, but it’s a simplified version that gets the idea across.
Imagine a room with two lamps, devices which can be switched on or off to change their status of “lit” to “unlit.” That’s pretty simple.
But now let’s add one button in the room that when pressed, changes the status of each lamp to the opposite of what it already is (switched on to switched off and vice versa). For what I’m planning to do, I need this to be a button that can be activated with one action (being pressed), not a device like a light switch that can be activated with two distinct actions (switching on or switching off).
The button is the part I’m having trouble with. I can do it, but it looks like this:
Basement is a dark room.
The red lamp is a device.
The red lamp is in basement.
The red lamp is switched on.
The red lamp is lit.
The blue lamp is a device.
The blue lamp is in basement.
The blue lamp is switched off.
The blue lamp is unlit.
Carry out switching on the red lamp:
now the red lamp is lit.
Carry out switching off the red lamp:
now the red lamp is unlit.
Carry out switching on the blue lamp:
now the blue lamp is lit.
Carry out switching off the blue lamp:
now the blue lamp is unlit.
The green button is in Basement.
Before pushing the green button:
if the red lamp is switched on:
if the blue lamp is switched on:
try silently switching off the red lamp;
try silently switching off the blue lamp;
say "click!";
stop the action;
if the red lamp is switched off:
if the blue lamp is switched off:
try silently switching on the red lamp;
try silently switching on the blue lamp;
say "click!";
stop the action;
if the red lamp is switched on:
if the blue lamp is switched off:
try silently switching off the red lamp;
try silently switching on the blue lamp;
say "click!";
stop the action;
if the red lamp is switched off:
if the blue lamp is switched on:
try silently switching on the red lamp;
try silently switching off the blue lamp;
say "click!";
stop the action;
The only way I can figure out how to do this is to code in every possibility for the two lamps: on/on, off/off, on/off and off/on. That’s not a big deal with two lamps, but what if I’d like for the button to control three or four lamps? Or ten? The number of possibilities gets out of control very fast. It’s not impossible to code, but I can’t help but think there’s a way to say the equivalent of “If the button is pressed: reverse the on/off status of the red lamp and reverse the on/off status of the blue lamp.”
Is there a way to say that?
Thanks in advance!