var x0 = msg.payload.x0;
var x1 = msg.payload.x1;
var x2 = msg.payload.x2;
var x3 = msg.payload.x3;
That's what I think could be it, without knowing what is coming into the function.
if the state of the motors is coming in multiple msg's, then you need to safe the state into context or flow variable to keep track of them.
a quick flow example;
[{"id":"a00a0735.0eb5b8","type":"inject","z":"95f61204.15452","name":"","topic":"motor1","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":262,"y":1368,"wires":[["d4c5a420.9a8e58"]]},{"id":"8d59f29f.ad995","type":"inject","z":"95f61204.15452","name":"","topic":"motor1","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":262,"y":1404,"wires":[["d4c5a420.9a8e58"]]},{"id":"633095bd.8216dc","type":"inject","z":"95f61204.15452","name":"","topic":"motor2","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":262,"y":1464,"wires":[["d4c5a420.9a8e58"]]},{"id":"6b321c7b.908b44","type":"inject","z":"95f61204.15452","name":"","topic":"motor2","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":262,"y":1500,"wires":[["d4c5a420.9a8e58"]]},{"id":"1642c43d.6a50fc","type":"inject","z":"95f61204.15452","name":"","topic":"motor3","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":262,"y":1560,"wires":[["d4c5a420.9a8e58"]]},{"id":"9bd997cd.b708c8","type":"inject","z":"95f61204.15452","name":"","topic":"motor3","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":262,"y":1596,"wires":[["d4c5a420.9a8e58"]]},{"id":"422559a0.3a73a8","type":"inject","z":"95f61204.15452","name":"","topic":"motor4","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":262,"y":1656,"wires":[["d4c5a420.9a8e58"]]},{"id":"59321b02.444154","type":"inject","z":"95f61204.15452","name":"","topic":"motor4","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":262,"y":1692,"wires":[["d4c5a420.9a8e58"]]},{"id":"d4c5a420.9a8e58","type":"function","z":"95f61204.15452","name":"","func":"var nr = parseInt(msg.topic.substring(msg.topic.length - 1))-1;\nvar count = 0;\ncontext.set(\"state[\" + nr +\"]\", msg.payload);\n\nfor (var i in context.get(\"state\")){\n \n if (context.get(\"state[\" + i +\"]\") === true ) {\n count++\n }\n msg.payload = count < 3?\"oke\":\"to Match\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":542,"y":1536,"wires":[["33fbaaa3.d24036"]]},{"id":"33fbaaa3.d24036","type":"debug","z":"95f61204.15452","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":674,"y":1536,"wires":[]}]
