Help needed Script to setswitch false when chest is empty and true when content is detected

Discussion in 'The Hangar Bay' started by Dracota, May 21, 2022.

Tags:
  1. Dracota

    Dracota Ensign

    Joined:
    May 14, 2017
    Messages:
    1
    Likes Received:
    0
    Good day, I am struggling to figure out how to get a script to work.
    I am trying to let my script pull a switch if there is content in a chest and turn the switch off if there is no content in the switch. I only get so far to turn the switch on when there is something in the chest just cant figure out how to use if and else. if I even should use it.

    This is the script (nope doesnt work)

    Targets:Tester
    {{#items E.S 'TesterKiste'}}
    {{Count}}{{Name}}
    {{Count}}{{i18n Key}}
    {{#test Count geq 1}}
    {{setswitch @root.E.S 'Schalter1' 'True'}}
    {{/test}}
    {{/setswitch}}
    {{#test Count in ''}}
    {{setswitch @root.E.S 'Schalter1' 'False'}}
    {{/test}}
    {{/test}}
    {{/setswitch}}
    {{/items}}
     
    #1
  2. Nathan Jurgens

    Nathan Jurgens Lieutenant

    Joined:
    May 18, 2016
    Messages:
    52
    Likes Received:
    5
    If there is nothing in the chest, the {{#items E.S 'TesterKiste'}} loop will not trigger (empty), so you can not have the check for that inside the loop

    Code:
    Targets:Tester
    {setswitch @root.E.S 'Schalter1' 'False'}}
    {{/setswitch}}
    {{#items E.S 'TesterKiste'}}
    {{Count}}{{Name}}
    {{Count}}{{i18n Key}}
    {{#test Count geq 1}}
    {{setswitch @root.E.S 'Schalter1' 'True'}}
    {{/setswitch}}
    {{/test}}
    {{/items}}
     
    #2
  3. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    Code:
    Targets:Tester
    {{set 'HaveItems' false}}
    {{#items E.S 'TesterKiste'}}
    {{Count}}{{i18n Id}}
    {{set 'HaveItems' true}}
    {{/items}}
    {{setswitch E.S 'Schalter1' Data.HaveItems}}
    A few little things you can still leave out and control the switch only once with the "correct" value
     
    #3
  4. Sephrajin

    Sephrajin Rear Admiral

    Joined:
    Dec 22, 2017
    Messages:
    916
    Likes Received:
    2,917
    Dont we need "@root." anymore?
     
    #4
  5. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    On top level you start with the @Root object in the scope, so only on top level commands you not need @Root.
    PS: BUT, if you change the scope with a sourrounding "if", "test" etc, your - old - code will fail.
     
    #5
    Sephrajin likes this.

Share This Page