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.

  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:
    60
    Likes Received:
    7
    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:
    808
    Likes Received:
    666
    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

Share This Page