Jump to content
C4 Forums | Control4

Break and Stop commands


ILoveC4

Recommended Posts

When is it appropriate to use the "break" command? Also, when is the "stop" command most often used? I can only think of one instance where I use the stop command, and if I understand it correctly it ends the script them, right?

Example:

IF xxxxxxx

then yyyyyyy

STOP

IF zzzzzzzz

then aaaaaaa

STOP

Would the STOP command stop the second IF statement from being checked, or would it only stop something nested below the stop statement?

Link to comment
Share on other sites


When is it appropriate to use the "break" command? Also, when is the "stop" command most often used? I can only think of one instance where I use the stop command, and if I understand it correctly it ends the script them, right?

Example:

IF xxxxxxx

then yyyyyyy

STOP

IF zzzzzzzz

then aaaaaaa

STOP

Would the STOP command stop the second IF statement from being checked, or would it only stop something nested below the stop statement?

In your example above the first stop command would prevent the second IF statement from running if the first IF statement was executed.

Link to comment
Share on other sites

Yeah, in my day, nothing but a GOTO was needed!

Actually, it was probably a JMP and/or LONGJMP, in assembly, of course.

:)

Seriously, Break is pretty common (it's also called 'continue' in some languages), and Stop is nothing but a 'return'.

The reason they're somewhat awkward is that there's no 'else' in the drag and drop programming, so you have to use if...then and then break to implement an else.

RyanE

Link to comment
Share on other sites

Yeah, in my day, nothing but a GOTO was needed!

Actually, it was probably a JMP and/or LONGJMP, in assembly, of course.

:)

Seriously, Break is pretty common (it's also called 'continue' in some languages), and Stop is nothing but a 'return'.

The reason they're somewhat awkward is that there's no 'else' in the drag and drop programming, so you have to use if...then and then break to implement an else.

RyanE

which brings me to my next question....always wondered about the absence of else...could it go in sometime in the future?

Link to comment
Share on other sites

Here's how I would use it.

When the Variable Current Media Changes in Room->ILoveC4's Party Shack

IF Current Media Selction = "Vanilla Ice"

-> STOP "CollaborateAndListen"

-> BREAK

IF Current Media Selection = "MC Hammer"

-> STOP "HammerTime"

-> BREAK (it down)

While "HammerTime" is TRUE

-> LOOP "ohohohoh"

Link to comment
Share on other sites

I think thecodeman's example is certainly valid.

An actual use of code won't be clearer as to when you should use it.

The Vanilla Ice / MC Hammer part is pretty much equivalent to an if/then/elseif.

RyanE

Link to comment
Share on other sites

Here's an example of the break command (more like the java language than C4 script, but the logic is the same. Basically it cause you to break out of the loop after the first pass through.

while ( i < 5) {

i=doSomething();

if(i<0) break; // jump out of the loop

}

Google "java break command" for more examples.

I know it's not a real life example of a C4 application of the command.

Link to comment
Share on other sites

Here's an example of the break command (more like the java language than C4 script, but the logic is the same. Basically it cause you to break out of the loop after the first pass through.

while ( i < 5) {

i=doSomething();

if(i<0) break; // jump out of the loop

}

Google "java break command" for more examples.

I know it's not a real life example of a C4 application of the command.

Thanks Bebster, I understand how it works in Java. I was looking for that real life example of a C4 application of the command.

Based on what Matt says it sounds like it is only used with loops? That would explain why I am unfamiliar with it, I have never used a loop and don't think it is even possible for me to program a loop.

Is that true, that they are only used with loops? If not, I would still love an example.

Link to comment
Share on other sites

Delay — Allows you to delay an action from taking place.

Stop—Allows you to stop all programming.

Break—Allows you to break out of a while loop when a specified condition is met and return to the programming outside of the loop.

I am not going to show you in a while loop, I recommend against them. If programmed incorrectly you could really “jack up” your system.

Stick with conditionals.

Link to comment
Share on other sites

Thanks Matt, I am not looking for information on a while loop. I was mostly just curious if the "break" command had a use outside of the loop. I don't think I even have the ability to add loops, do I?

Link to comment
Share on other sites

^Yeah, I don't get this at all. You can only evaluate something once (like when a button is pressed). Looping doesn't seem possible or desirable as already mentioned. HC-1000 would be the "base model" controller in that case :)

Link to comment
Share on other sites

^Yeah, I don't get this at all. You can only evaluate something once (like when a button is pressed). Looping doesn't seem possible or desirable as already mentioned. HC-1000 would be the "base model" controller in that case :)

I could see how it would be beneficial to create a makeshift timer before that was possible using the new agent. For example:

To create a :60 second timer you could:

When button three is released set variable "timer" to 60

->Delay one second

->Variable "timer" = -1

->If variable "timer" >0

Loop

I don't know how the loop looks on programming, but that could be a way to create a timer where the length of timer was easily adjustable. Of course the timer agent makes this obsolete. I cannot even think of a time when using a loop would be desirable, and it sounds like the break command is only used in conjunction with a loop.

Hell, while were at it does anyone have an example of what a loop might be used for?

Link to comment
Share on other sites

This is how you could use a "loop". It's pretty complex imo and I can see how they would want to leave it out. Lots of things to think about, just for a bathroom fan on a timer like this.

Yes, for example, make a button press turn on a fan, and then turn it off after a certain period of time. You can also increase the time the fan remains on in 5 minute increments.

The timer variable is decremented like you described, but there's a delay of one second before the decrement for seconds.

From training:

Create two variables.

In the enclosed example, these variables are named “MasterFanCount” and “MasterfanBL”

To add 5 minutes to the fan time, increment the “MasterFanCount” numeric variable +300 and set the “MasterfanBL” Boolean variable to true

Once we place a while loop = true on the MasterfanBL Boolean variable, we can set a delay of 1 second and decrement (minus) 1 from 300 each second.

This represents a time object of 5 minutes each tap 300/60 = 5

Programming looks like:

When Master Bathroom - Bathroom Fan Top Button is pushed

Variables MasterFanCount = MasterFanCount + 300 (this is seconds, giving you 5 minutes each tap)

Variables MasterFanBL = True

Here is the while statement made to the Boolean variable

Notice the MasterFanCount numeric variable is being decremented by 1 each second

Programming looks like:

When the variable Variables-MasterFanBL changes

(loop) While variables MasterFanBL is true

delay 1 second

variables-> MasterFanCount = Variables-> MasterFanCount -1

If the bathroom fan level changes, the conditional “If Light Off” will then set the boolean variable “MasterfanBL” to false the the numeric variable “MasterFanCount” to zero which turns off the fan.

Problem this avoids:

What if you turn off the fan from a Navigator? It doesn’t reset the count to a “0” and set the Boolean Variable to False as it should.

Programming looks like:

(On the Bathroom Fan Switch)

When Master Bathroom -> Bathroom Fan Level changes

? If Master Bathroom Light is off

variables-> MasterFanBL = False

variables-> MasterFanCount = 0

If the bottom button on the switch is pushed, then the numeric variable “MasterFanCount” = 0

Here is the conditional statement made to the numeric variable to turn off the fan.

When the variable Variables->MasterFanCount changes

If Variables-> MasterFanCount<1

Variables->MasterFanBL = false

Variables->MasterFanCount = 0

Turn Off the Master Bathroom -> Bathroom Fan

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.