Hi All,
Wondering if someone could help me.
Trying to get this code working for a friend. It has 2 limits -150 and 150. Its adds the last number to the new number and outputs it but will only allow to stay with in limits. And has a reset back to 0.
For some reason this works on my Raspi Pi 4 but not on my friends computer.
[{"id":"d2492f6838bf6632","type":"function","z":"3a22222acce369c8","name":"","func":"var max = 500;\nvar min = global.get ('socvar');\nvar total = context.get('total');\nif (msg.reset) {\ntotal = 0;\n}\nelse {\ntotal = total + msg.payload\n}\nif (total > max) total = max;\nif (total < min) total = min;\ncontext.set('total', total);\nmsg.payload = total;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1360,"y":1400,"wires":[["252eefed571911b3"]]},{"id":"252eefed571911b3","type":"debug","z":"3a22222acce369c8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1660,"y":1400,"wires":[]},{"id":"35eb22f321d14cdc","type":"inject","z":"3a22222acce369c8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":1140,"y":1320,"wires":[["d2492f6838bf6632"]]},{"id":"736abd7f5ee98b8f","type":"inject","z":"3a22222acce369c8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"-10","payloadType":"num","x":1130,"y":1460,"wires":[["d2492f6838bf6632"]]}]
I did input this code into an online JSON checker and it flags some errors. https://jsonlint.com/
Says
Error: Parse error on line 1:
var max = 500;,var
^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'
Would someone please help me debug this code please? Im not a coder
Any help would be much appreciated
Thanks
Gareth