Setting blub color based on month


#1

I currently have a piston that turns on an outdoor light and sets its color to blue for my halloween display. There are 3 different conditions that cause the light to turn on. My plan is to change it to orange for Thanksgiving, red for Christmas, green for March, etc. I could do that by just modifying the script each month but was thinking it would nice to just set a variable and have a case (switch) block that sets the color based on month. What would be the best way to go about doing that?


#2

It can be as simple as creating a SWITCH block, using the $monthName system variable.

execute
  switch ($monthName})
     case 'October':
          set light color 'orange'
     case 'March':
          set light color 'green'
   end switch
end execute

#3

Does it matter where that execute block is in my code? Will it always set the value in that switch statement when the piston executes? So I can delete the “setColor” function everywhere else?


#4

I would probably do something like this:

I don’t have any color-settable devices, so, I included pseudocode for your setcolor action at line 36.

And, yeah, each “day” at sunset when the piston fires, it will parse through the switch statement first, setting the lightColor variable. When this piston is called on October 31, the light will come on with a “White” color. The next day, on November 1, the light will come on with an “Orange” color.


#5

Thanks, that looks a lot better. I tried the code you had above and quickly learned that it wouldn’t work that way because the switch statement got executed and turned the lights on every time a trigger happened which resulted in undesireable results. The second set of code looks a lot better, it should work what I’m trying to do.