Jump to content
C4 Forums | Control4

Programming Control


MarkD

Recommended Posts

Oh how I wish there were "else" and "else if" options in Composer "Programming Control"...!

I know there's a != (not equals), etc., but it's a real pain when I want to do more complex programming that takes a number of things into account... such as determining outdoor light options based on the time of day, time of year (ie: Xmas lights), holiday mode, alarm disarmed/armed home/armed away status... and a variable for when we're entertaining...!

Link to comment
Share on other sites


Can you give an example of when an "else if" statement would be used? I am not a computer programmer, but I have never ran into a situation where I couldn't figure out how to get any and all conditional statements taken into consideration when executing programming.

Link to comment
Share on other sites

I'll see if I can come up with a truly good example... all the ones coming to me now are lame.

But probably, I should also have submitted my wish for "and" and "or" modifiers too.

Yeah, I was a programmer once upon a time. And you are right -- there is always a way to get around the lack of an "else", but life would be easier with it. I haven't actually been stumped yet. I just love efficiency! In traditional programming, when the compiler sees "if ... else if ... else if ... else ... end if", it knows that once it has found one condition that is "true" and executes the corresponding code, it can skip over all the remaining conditions to evaluate and proceed straight to the "end if", which is much more efficient than evaluating a bunch of "if" conditions.

But a guy can dream, right? =)

Link to comment
Share on other sites

Just make sure and issue a STOP command after the conditional and the subsequent programming is executed. That will kill everything afterwords and make it more efficient.

Just a thought.

Keep the ideas coming, I am a big fan of sharing opinions and making requests. If nobody requests anything, it probably won't ever happen.

Link to comment
Share on other sites

Hmmm... this reminds me of something I did do recently... but I can't remember what it was! Anyways, I did check for my "else" conditions and if they were true I inserted a "stop" command.

Great minds... ;-)

Link to comment
Share on other sites

  • 8 months later...

A programming trick for checking multiple conditions is to use powers of two to represent that state of each item of interest. Add all those to a numeric variable, and then you can easily check for any single or combination of states.

An example may clarify.

Define variable Conditions as numeric, initially set to 0.

If ChristmasTime set Conditions = Conditions + 1 [2 to the 0th power]

If InHolidayMood set Conditions = Conditions + 2 [2 to the 1st power]

If Alarm is Stay set Conditions = Conditions + 4 [2 to the 2nd power]

If Alarm is Away set Conditions = Conditions + 8

If Entertaining set Conditions = Conditions + 16

Now you can uniquely check for any specific set of conditions by adding each power of 2 variable for the conditions you want. For example,

If Conditions = 19 turn on music. [ChristmasTime, InHolidayMood, Entertaining, and Alarm disarmed]

Or,

If Conditions = 6 turn off JackOLantern light. [inHolidayMood (non Christmas) and Alarm set for Stay (going to bed for the night)]

--David

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...