Hello,
I am trying to make a flow to go back and forward in an array of colors, and for the most part it works
But when I go from pressing "forward" to "backward", the first time I press backward it goes forward in the array and then starts going backwards, same happens the other way around, when going from backward to forward.
Could anyone tell me why this happens and how to fix it ?
[{"id":"5062e14b16b0ea34","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"5730495f3e741a0b","type":"function","z":"5062e14b16b0ea34","name":"color backward","func":"var colors = flow.get(\"colors\");\n\nvar x = colors.length - 1;\nvar count = flow.get(\"count\");\nvar y = isNaN(count);\n\nif(y === true ){\n count = 0;\n flow.set(\"count\", count);\n}\n\nvar currentColor = colors[count];\ncount--;\n\n\nif(count < 0){\n count = x;\n}\n\nflow.set(\"count\", count);\nmsg.payload = {\"color\":{\"rgb\": currentColor}};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":340,"wires":[["c625da7696b47a08"]]},{"id":"5908ca63a8aa9687","type":"function","z":"5062e14b16b0ea34","name":"color forward","func":"var colors = flow.get(\"colors\");\n\nvar x = colors.length - 1;\n\nvar count = flow.get(\"count\");\nvar y = isNaN(count);\n\nif(y === true ){\n count = 0;\n flow.set(\"count\", count);\n}\nvar currentColor = colors[count];\ncount++;\n\n\nif(count > x){\n count = 0;\n}\nflow.set(\"count\", count);\nmsg.payload = {\"color\":{\"rgb\": currentColor}};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":630,"y":260,"wires":[["c625da7696b47a08"]]},{"id":"c625da7696b47a08","type":"debug","z":"5062e14b16b0ea34","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":300,"wires":[]},{"id":"c6aa9299edd98641","type":"inject","z":"5062e14b16b0ea34","name":"color array","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"one\",\"two\",\"three\"]","payloadType":"json","x":420,"y":180,"wires":[["3004e429aad190ac"]]},{"id":"3004e429aad190ac","type":"function","z":"5062e14b16b0ea34","name":"Set colors","func":"var x = msg.payload;\nflow.set(\"colors\", x);\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":180,"wires":[[]]},{"id":"d9c32ef22a7782a6","type":"inject","z":"5062e14b16b0ea34","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":420,"y":260,"wires":[["5908ca63a8aa9687"]]},{"id":"3d5ddee51f141f3b","type":"inject","z":"5062e14b16b0ea34","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":420,"y":340,"wires":[["5730495f3e741a0b"]]}]