Jump to content
C4 Forums | Control4

Programming wish: EXECUTE


Bedspread

Recommended Posts

In the C4 programming "language" there is the ability to trigger events based on the change of a variables state.

"WHEN X CHANGES" DO THE FOLLOWING.

I use this very often and it is very much like a macro or subroutine in other programming languages.

My suggestion is to add the ability to run these subroutines without having to change the state of the variable but simply to EXECUTE the code even if the variable did not change state.

For example:

One thing that I do often is to set up a boolean variable as a flag and then when the flag changes from TRUE to FALSE or FALSE to TRUE, trigger certain events (useful for LED color changes that signify conditions and useful for many other things)

Variable: STATUS_CHECK

WHEN STATUS_CHECK changes:

IF STATUS_CHECK is TRUE

DO A, B, C, D, E, F

IF STATUS_CHECK is FALSE

DO I, J, K, L, M, N

I would like to have the ability to execute these types of subroutines even if the STATUS_CHECK variable has not changed state. It would be something like: EXECUTE STATUS_CHECK

Link to comment
Share on other sites


You can do this now, if you just use a different boolean variable as a trigger.

So, put the code that checks Variable X into a 'When Variable Y' changes, and in the 'When Variable X Changes' event, toggle Variable Y.

Then, if you want to manually trigger it, toggle Variable Y.

Somewhat convoluted, but it'd work fine.

RyanE

Link to comment
Share on other sites

In the C4 programming "language" there is the ability to trigger events based on the change of a variables state.

"WHEN X CHANGES" DO THE FOLLOWING.

I use this very often and it is very much like a macro or subroutine in other programming languages.

My suggestion is to add the ability to run these subroutines without having to change the state of the variable but simply to EXECUTE the code even if the variable did not change state.

For example:

One thing that I do often is to set up a boolean variable as a flag and then when the flag changes from TRUE to FALSE or FALSE to TRUE, trigger certain events (useful for LED color changes that signify conditions and useful for many other things)

Variable: STATUS_CHECK

WHEN STATUS_CHECK changes:

IF STATUS_CHECK is TRUE

DO A, B, C, D, E, F

IF STATUS_CHECK is FALSE

DO I, J, K, L, M, N

I would like to have the ability to execute these types of subroutines even if the STATUS_CHECK variable has not changed state. It would be something like: EXECUTE STATUS_CHECK

I totally would use this. I have some strange side-effect from 1.8 that likes to randomly change the LED color state even if he load state did not change. What he is describing would band-aid this.

Link to comment
Share on other sites

You can do this now, if you just use a different boolean variable as a trigger.

So, put the code that checks Variable X into a 'When Variable Y' changes, and in the 'When Variable X Changes' event, toggle Variable Y.

Then, if you want to manually trigger it, toggle Variable Y.

Somewhat convoluted, but it'd work fine.

RyanE

Very true but I'm of the school that code should be efficient and that the most brief, minimal code is best. The least amount of code and logic necessary to do a job is always the best code.

So your suggestion is:

When Y changes

IF X is TRUE

DO A, B, C, D, E

IF X is FALSE

DO I, J, K, L, M

Now there is more code necessary to determine if it is time to manually change the state of Y so that the code under X can be executed. As you say it is convoluted and as the project grows in complexity and size this approach really increases the amount of code necessary.

Someone above hinted that the EXECUTE command may be in our future. I hope that it's true.

Link to comment
Share on other sites

Yes, two lines of code.

So keep this:

When Y changes

IF X is TRUE

DO A, B, C, D, E

IF X is FALSE

DO I, J, K, L, M

And add this:

When X changes

Toggle Y

I haven't heard of an 'Execute' command (other than the existing 'Execute' button in Composer), so I wouldn't hold your breath.

RyanE

Link to comment
Share on other sites

Yes, two lines of code.

So keep this:

When Y changes

IF X is TRUE

DO A, B, C, D, E

IF X is FALSE

DO I, J, K, L, M

And add this:

When X changes

Toggle Y

I haven't heard of an 'Execute' command (other than the existing 'Execute' button in Composer), so I wouldn't hold your breath.

RyanE

Ok. I'll keep breathing. No big deal...

Thanks for your input.

Link to comment
Share on other sites

sorry if this is redundant, but i would like the ELSE command added. testing for TRUE and FALSE does accomplish the same thing but its more verbose and ELSE can handle more and reduces the need for another IF COMMAND.

IF X IS TRUE DO COMMANDA ELSE DO COMMANDB

Link to comment
Share on other sites

sorry if this is redundant, but i would like the ELSE command added. testing for TRUE and FALSE does accomplish the same thing but its more verbose and ELSE can handle more and reduces the need for another IF COMMAND.

IF X IS TRUE DO COMMANDA ELSE DO COMMANDB

You can create your own ELSE construct if you use a variable.

Boolean Variable: MYELSE

Set MYELSE = TRUE

IF X

DO <abcdef>

Set MYELSE = FALSE

IF MYELSE = TRUE

DO <defghi>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.