Quote:
Might I suggest $S.Toggle(0) for turning off then


In the interest of maintining the level of pedantry in this thread - No, you may not \:\)

Maybe it doesn't translate very well into other languages, but "Toggle" in english when used in a programming context means "change to the alternate state".

For booleans, it has the same effect as NOT, so the following two statements are equivalent:
 Code:
1 - $oSwitch.State=Not $oSwitch.State
2 - $oSwitch.Toggle


For a 1Hz (2Hz? someone help me out) flashing lamp effect:
 Code:
while "true"
  $oSwitch.Toggle
  Sleep 0.5
Loop


Perhaps I should have described the script better as a "lightbulb change emulator", as it emulates what people do, rather that the sensible way of doing it which would have been less amusing - people burning their fingers through ineptitude is always going to be funny.

When a bulb doesn't work, people tend to flick (toggle) the switch two or three times before the fact that it is clearly not working sinks in. Then they change the bulb, forgetting to check the state of the lightswitch first.

Now, you could check $oSwitch.State at the start and toggle the switch if true. This would allow you to remove the later IsHot checks and and lose the entire RunFingersUnderColdWater() UDF making the code much shorter.

However, the problem with this is twofold:
  1. Push type switches often don't have a clear on/off state, so $oSwitch.State will be undetermined.
  2. Another routine may have toggled the switch state after you checked it. You can get around this if the switch supports the "Lock" method, but most lamp switches do not.