Logic help needed...

Discussion in 'Pascal Logic Code Examples' started by Jasp, Jun 7, 2011.

  1. Jasp

    Jasp

    Joined:
    May 25, 2010
    Messages:
    24
    Likes Received:
    0
    Location:
    Melbourne
    Hi All,

    Just after some assistance as I dabble in a little bit of simple logic. (Although not seeming simple at the moment.)

    The scenario we're trying to achieve is the ability to turn of a set of a dozen highbay lights after the alarm has been turned off for 1 hour.

    At the moment, the alarm is set to turn on a set of lights in our reception area, activate a blind control to open in the boardroom and also lift the rollerdoor for access into the factory when Disarmed.

    I have created a new scene with All the highbay lights in it and tried setting a timer to count to 3600 secs (1hr), but it doesn't seem to be doing what i want.

    Please have a look at the following code as I am stumped:

    {Turn High Bays Off after 1 hr from Alarm being DISARMED}
    if (GetSceneLevel("DOWNSTAIRS ALARM DISARM") = -1) { Scene Set ? }then
    begin
    TimerStart(1);
    if TimerTime(1) = 3600 then
    begin
    SetSceneLevel("HIGHBAYS", 0%, 0);
    TimerStop(1);
    end;
    end;

    Hope someone can shed some light...

    Jamie
     

    Attached Files:

    Last edited by a moderator: Jun 7, 2011
    Jasp, Jun 7, 2011
    #1
    1. Advertisements

  2. Jasp

    mattyb

    Joined:
    Jul 29, 2005
    Messages:
    77
    Likes Received:
    0
    Location:
    Sydney, Australia
    Hi

    By using "If" your code is running on every cycle of the logic engine when the "Disarmed" scene is set. This means TimerStart(1) will run on every cycle, and this resets the timer - so the timer will never get to 3600!

    You need to use "once".

    You're generally best to separate the code that starts the timer from the code that runs once the timer reaches the desired time e.g.

    Code:
    once (GetSceneLevel("DOWNSTAIRS ALARM DISARM") = -1) { Scene Set ? }then
    begin
     TimerStart(1);
    end;
    
    once TimerTime(1) > 3600 then
    begin
    SetSceneLevel("HIGHBAYS", 0%, 0);
    TimerStop(1);
    end; 
    
    I use...
    Code:
    once TimerTime(1) > 3600 then
    ...as I believe there's a slim chance the logic engine could miss the exact point where...
    Code:
    once TimerTime(1) = 3600 then
    ...although I may just be perpetuating a myth!

    Hope that helps.

    Cheers

    Matt
     
    mattyb, Jun 7, 2011
    #2
    1. Advertisements

  3. Jasp

    Jasp

    Joined:
    May 25, 2010
    Messages:
    24
    Likes Received:
    0
    Location:
    Melbourne
    Thanks for your help!

    While trialing a few others before your post, I decided to just pulse them after 1 hr from within the scene that controls the roller door, reception lights etc.

    Seems to be working fine for now.
    Thanks again.
     
    Jasp, Jun 7, 2011
    #3
  4. Jasp

    mattyb

    Joined:
    Jul 29, 2005
    Messages:
    77
    Likes Received:
    0
    Location:
    Sydney, Australia
    Hey, no worries. You found the easiest way to do it anyway!

    Cheers

    Matt
     
    mattyb, Jun 7, 2011
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.