script

Discussion in 'General Discussion' started by Newbie, Sep 28, 2012.

  1. Newbie

    Newbie

    Joined:
    Jun 16, 2010
    Messages:
    45
    Likes Received:
    0
    Location:
    South Africa
    Hello

    I got this piece of script that im trying to get working...

    i want is when sensor A detects movement AND sensor B(IN THIS ORDER A FIRST THEN B SECOND) then it going to plus 1...

    and then also vice versa to minus 1...

    So this is what my code looks like...

    Once (GetLightingState("A")=ON) AND (GetLightingState("B") THEN
    Begin

    Trigger := Trigger +1;

    End;


    Once Once (GetLightingState("B")=ON) AND (GetLightingState("A") THEN
    Begin

    Trigger := Trigger -1;
    End;

    I know the counter is working, but i dont know how to get to logic to look at A first then at B, and then at B then at A...

    Thanks You
     
    Newbie, Sep 28, 2012
    #1
  2. Newbie

    Roosta

    Joined:
    Nov 22, 2011
    Messages:
    560
    Likes Received:
    1
    Location:
    Australia
    I think what you are trying to do might be destined to fail, but without giving more info you could try something like this

    ONCE A = ON THEN
    ONCE B = ON THEN
    COUNTER +1
    END
    END

    ONCE B = ON THEN
    ONCE A = ON THEN
    COUNTER -1
    END
    END

    This code above may or may not work depending on how u have your inputs configured..

    OR

    ONCE A = ON AND B = OFF THEN
    ONCE B = ON THEN
    COUNTER +1
    END
    END

    ONCE B = ON AND A = OFFTHEN
    ONCE A = ON THEN
    COUNTER -1
    END
    END

    Not really sure if either will work..

    If you feel like sharing what you are trying to achieve in real world terms we might be able to help with a better solution..

    Cheers.
     
    Roosta, Sep 28, 2012
    #2
  3. Newbie

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,548
    Likes Received:
    178
    Location:
    Adelaide, Australia
    Try

    Once GetLightingState("B") then
    if GetLightingState("A") then
    begin
    trigger := trigger + 1;
    setLightingState("A", OFF);
    setLightingState("B", OFF);
    end;

    Once GetLightingState("A") then
    if GetLightingState("B") then
    begin
    trigger := trigger - 1;
    setLightingState("A", OFF);
    setLightingState("B", OFF);
    end;

    The idea is to wait on the second sensor, then see if the first one is already on.
    Set the timer for each sensor to be the maximum time you want between passing each sensor.

    The nested ONCE statements are interesting. I'm surprised it compiles. Not really sure what the logic engine would even do with it.
     
    Last edited by a moderator: Sep 28, 2012
    Ashley, Sep 28, 2012
    #3
  4. Newbie

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    This is the correct way to solve the problem. It may not be necessary to switch off A and B though, as they are probably controlled by the sensor.

    You are correct in that nested once statements should never be used. There is a warning in the help file about it.
     
    Darren, Sep 29, 2012
    #4
  5. Newbie

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,548
    Likes Received:
    178
    Location:
    Adelaide, Australia
    The reason I included the code to reset A and B was to ensure only one of the ONCE statements were ever executed in a scan. If both sensors were triggered between scans (although unlikely) both ONCE statements would be fired and cancel each other out. This may, of course, be desirable depending upon the actual requirments. Also it re-enables the ONCE statements. If the sensor timer is set to a long value the ONCE statements will not be executed again untl the sensors time-out. Resetting the groups will allow the ONCE statements to trigger immediately again if someone walks through then straight back agian.

    I don't think the HELP specifically mentions nested ONCE statements. I could only find a reference to ONCE inside loops and ONCE inside IF statements.
     
    Last edited by a moderator: Sep 29, 2012
    Ashley, Sep 29, 2012
    #5
  6. Newbie

    Newbie

    Joined:
    Jun 16, 2010
    Messages:
    45
    Likes Received:
    0
    Location:
    South Africa
    i have tried using if statement, but i kept getting scan errors..

    Im trying to say that when Sensor A and maybe within 3sec B also senses movement, you are going to have a +1 on your trigger count, which then from there if my trigger count is higher than 0 then the lights is going to go on..

    And this must just keep addind and subtracting depending in which order the sensors are going to be triggered..So if the count is higher than 0 then switch on when 0 switch off..
     
    Newbie, Oct 9, 2012
    #6
  7. Newbie

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    If you need to consider the delay between the two events, the it will need to be done slightly differently. This should work:

    Code:
    once GetLightingState("A") then
    begin
      TimeA := time;
      if (time > TimeB) and (time - TimeB < 3) then
        Trigger := Trigger - 1;
    end;
    
    once GetLightingState("B") then
    begin
      TimeB := time;
      if (time > TimeA) and (time - TimeA < 3) then
        Trigger := Trigger + 1;
    end;
     
    Darren, Oct 10, 2012
    #7
  8. Newbie

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,548
    Likes Received:
    178
    Location:
    Adelaide, Australia
    Alternatively just set to timer on the sensors to 3 seconds. If you don't pass the second sensor within that time it will have expired and the IF statment will not be triggered and the count left unchanged.
     
    Ashley, Oct 10, 2012
    #8
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.