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}}
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}}
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
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.