How to convert this to a for-each loop


#1

1) Give a description of the problem
I would like to use loops for this (and many other things) but I seem to be fundamentally not grasping the best way to do it. I have instead brute-forced it by adding my 3 doors. This is all well and good when there are only 3 but for some sensors it will be a huge PITA to copy/paste each block and god forbid I need to make a change to all of them. I’m a developer and so it’s really annoying me that I’m apparently too stupid to make basic forEach loops work. I would REALLY appreciate if someone could either point me in the right direction or even re-write my posted script so it works the same but does it in a loop.

2) What is the expected behaviour?
Not sure

3) What is happening/not happening?
Not Sure

4) Post a Green Snapshot of the pistonimage

5) Attach logs after turning logging level to Full
N/A


#2

Re-vamped your piston to:

… where the “Unknown Devices” are your “Contact Sensor 1” , “Contact Sensor 2”, etc.

Haven’t tested this though, LOL …

This piston will write to the fuel stream for all the sensors if any of the contact sensor changes, while yours writes to the stream for only the contact sensor that changes.

Adding a restriction to the 2nd IF block to test for the $currentEventDevice should make it behave like your original piston: {$device} is equal to {$currentEventDevice}


#3

For future reference, copying/pasting code (of any size) takes me about 2 seconds using this method.


Also, for what it’s worth, you likely already have a piston that is monitoring Contact Sensor 1, and another that is monitoring Contact Sensor 2. If it were me, I would simply inject one block from your original post into those pistons. (there is no need to have multiple pistons firing off each time the door opens or closes) This should yield much more reliable results…


Edit:
I updated the wiki, and fixed the link here.