Author Topic: How can I loop this script?  (Read 1291 times)

Frunple

  • Hero Member
  • *****
  • Posts: 774
    • View Profile
How can I loop this script?
« on: December 31, 2010, 06:28:51 am »
lighting.TurnOffLight(16);
System.Sleep((30) * 1000);
if ( lighting.LightOnOffs[16] == true )
{
}


Basically I have a light that is "troublesome" at times, must get some noise at different times because it doesn't always turn off in the morning. It's my driveway light and I have it set to turn on 5 minutes before my usual leave time and go off 20 minutes later. I'm sick of coming home and seeing it still on so I thought I'd do the above, but I want rerun this until the light on/off shows false.
I thought maybe a "go to line x" in the action list would be good (ie line 1= turn off light, line 2 = pause, line 3 = if light is on, goto line 1, line 4 = if light is off, end) but the line numbers are lost in the scripts so thats no good.
So how can I loop this until the light is off??

John Hughes

  • Administrator
  • Hero Member
  • *****
  • Posts: 2852
    • View Profile
    • Codecore Technologies
Re: How can I loop this script?
« Reply #1 on: December 31, 2010, 09:31:35 am »
You probably don't want it to inadvertently run forever so I would put a timeout in there as well...

Code: [Select]
lighting.TurnOffLight(16);

dt = DateTime.Now.AddMinutes( 5 );
while ( lighting.LightOnOffs[16] == false && DateTime.Now < dt )
{
System.Sleep(30 * 1000);
lighting.TurnOffLight(16);
}

But before you try this I would verify that the LightOnOffs behaves the way you expect it to. Ie, make sure that the appropriate element is false after you instruct the light to turn on but it fails to do so.

John Hughes
Codecore Technologies

Frunple

  • Hero Member
  • *****
  • Posts: 774
    • View Profile
Re: How can I loop this script?
« Reply #2 on: January 02, 2011, 06:18:49 am »
If I'm not mistaken (very possible), wouldn't that cause it to run for 5 minutes regardless of whether the light turned off or not?
Isn't there a way to detect that the light is off and stop the script?
I don't know that it even matters, just curious really.

And also, my problem is that the light isn't turning off so the:

while ( lighting.LightOnOffs[16] == false && DateTime.Now < dt )

may see a value of true so will it still perform the indented?
« Last Edit: January 02, 2011, 06:54:02 am by Frunple »

John Hughes

  • Administrator
  • Hero Member
  • *****
  • Posts: 2852
    • View Profile
    • Codecore Technologies
Re: How can I loop this script?
« Reply #3 on: January 02, 2011, 10:28:55 pm »
Well that's embarassing... you are right.  :o

It should read:

Code: [Select]
lighting.TurnOffLight(16);

dt = DateTime.Now.AddMinutes( 5 );
while ( lighting.LightOnOffs[16] == true && DateTime.Now < dt )
{
System.Sleep(30 * 1000);
lighting.TurnOffLight(16);
}
John Hughes
Codecore Technologies