tfmeier Posted December 26, 2015 Share Posted December 26, 2015 I'm trying to run 10 times through an IF statement but it executes once only; e.g *** Start of code Variable X=1 IF Variable X <= 10 (via conditionals) Command x X=X+1 *** End of code So based on my limited understanding Command x should be executed 10 times before the evaluation of Variable X = 11 and so command X will no longer be executed. Trouble is it runs only once. What do I need to do to stay in this IF statement? Any help much appreciated Link to comment Share on other sites More sharing options...
jfh Posted December 26, 2015 Share Posted December 26, 2015 I think you want "While", which your dealer will have to do - not available in HE. Your code will always end up with X=2. you could put the code in the event where variable X changes and just stop when X > 10 Link to comment Share on other sites More sharing options...
Cyknight Posted December 26, 2015 Share Posted December 26, 2015 Stay away from loops/while statements, there's a reason it's been blocked. Please explain what it is you want - a timed counter of some sort is my guess- use a timer, repeatin When (event trigger) start timer x When timer x expires variable y = y+1 When variable y changes IF variable y <= 10 blah blah IF variable y >10 blah blah Link to comment Share on other sites More sharing options...
Matt Lowe Posted December 26, 2015 Share Posted December 26, 2015 you could get this to loop. create a macro go to your programming section if this happens then x=1 execute macro in the macro programming if x </= 10 command x add 1 to variable execute macro you may want a 1 or 2 second delay in there while testing in case you do not nest this properly or it may make it hard to stop if it gets stuck in a loop PROGRAM AT YOUR OWN RISK Link to comment Share on other sites More sharing options...
Cyknight Posted December 26, 2015 Share Posted December 26, 2015 Now if that isn't what you want - to do what I think you're trying to say there, you simply want to add that IF statement multiple times with a small delay each time: Variable X=1 IF Variable X <= 10 (via conditionals) Command x X=X+1 delay 200ms Variable X=1 IF Variable X <= 10 (via conditionals) Command x X=X+1 delay 200 ms Variable X=1 IF Variable X <= 10 (via conditionals) Command x X=X+1 etc Link to comment Share on other sites More sharing options...
Cyknight Posted December 26, 2015 Share Posted December 26, 2015 then again, if you want something to happen 10 times at the start of the event, why not just: When (event trigger) Command X delay 200ms Command X delay 200 ms and so on as many times as you want. Link to comment Share on other sites More sharing options...
Matt Lowe Posted December 26, 2015 Share Posted December 26, 2015 yea some more info on exactly what you want to happen will help narrow this down Link to comment Share on other sites More sharing options...
tfmeier Posted December 27, 2015 Author Share Posted December 27, 2015 Thanks for the responses so far and sorry guys, was late when I posted this yesterday so it may not have been too clear. My 8 y.o. daughter was asking me whether I could change the lights on the 3 button keypad to some colors given it was Xmas. Silly me said yes and so I picked up this mini project Essentially I'd like to use the scheduler and create a trigger with the sunset event running until sunrise. Within these two (time) end points I run a couple of LED color change patterns on the keypads throughout the house (Set LED x color to <color> on <keypad>). The color change patterns stop at sunrise (alternatively I use the same starting point; i.e. sunset but a different end point; e.g. midnight when everyone's asleep). So I guess using a macro (as Matt suggested) I'd have to check for the sunset/sunrise condition and possible start a timer when the sunset event starts (i.e. the macro runs until sunset indicated through a variable Z). A second scheduler creates a sunrise event which then is used to set a corresponding flag; i.e. variable Z. Re variables I assume these are 'global' as in regardless where I define 'x' I can read the value of 'x' to determine what to do, right? Clearer what I'm trying to do? Link to comment Share on other sites More sharing options...
Matt Lowe Posted December 27, 2015 Share Posted December 27, 2015 i would create a sheduler even for sunset when sunset happens set leds to the colors you want at sunrise set them back if you are trying to have them constantly changes colors you will likely end up slowing down your entire system or cause director to crash depending on how many keypads you are trying to change Link to comment Share on other sites More sharing options...
Matt Lowe Posted December 27, 2015 Share Posted December 27, 2015 or if you do want them to change all the time just be sure to put about 10 second timer in there at sunset start timer when timer expires if its midnight stop change leds colors start timer this will continally loop and you can start it on any given event Link to comment Share on other sites More sharing options...
Cyknight Posted December 27, 2015 Share Posted December 27, 2015 29 minutes ago, Matt Lowe said: or if you do want them to change all the time just be sure to put about 10 second timer in there at sunset start timer when timer expires if its midnight stop change leds colors start timer this will continally loop and you can start it on any given event Err. Just use a REPEATING 10 second times Use schedule to start timer (and set colors), and stop timer (and set colors) When timer expires variable +1 when variable changels if variable =1 -change to color x if variable =2 -change to color y If variable =>3 -change to color z set variable to 0 Link to comment Share on other sites More sharing options...
Cyknight Posted December 27, 2015 Share Posted December 27, 2015 Alternatively, on timer expire you can set that variable to a random number instead of adding 1 to mix things up. Link to comment Share on other sites More sharing options...
tfmeier Posted January 4, 2016 Author Share Posted January 4, 2016 Guys, thanks for the input. Works fine now with your help. Here's what I've done: Agents Created a Scheduler Agent X to execute daily at Sunset until the end of the festive season Created a Timer Agent Y with a certain interval Programming Created an event on the Scheduler Agent X to start the timer Y created under on the Timer Agent > When scheduled event X executes Start Timer Y Added the main code to the Timer Event "When Timer Y expires" The code starts with an IF condition to specify the end time (e.g. midnight) and off color (e.g. black) to "switch off" the light show at midnight. IF condition finishes with a Stop statement to stop code execution Rest of the code deal with the color change patterns As mentioned all works as designed with your help. Thanks again, guys! Link to comment Share on other sites More sharing options...
Matt Lowe Posted January 4, 2016 Share Posted January 4, 2016 you are welcome. a testament to how much control end users do have with control4! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.