var json = msg.payload;
for (var i in json) {if (json.hasOwnProperty(i)) { msg.id(json[i].X)=(json[i].X); msg.lat(json[i].Y)=(json[i].Y);}}
return msg;node.send({payload:msg.id});
global.set("name"+msg.id,value);for ( i = 1; i <= steps; i++ ){ var step(i) = global.get("step" + i);}--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/4f6dce22-ca44-4876-8919-48edd08dbbda%40googlegroups.com.
var steps = 5;
for ( i = 1; i <= steps; i++ ){ global.set("step"+i,1);}var step1 = global.get("step1");
var step2 = global.get("step2");
var step3 = global.get("step3");
var step4 = global.get("step4");
var step5 = global.get("step5");
for ( i = 1; i <= steps; i++ ){ var step(i) = global.get("step" + i);}Roger,there isn't quite enough information in that snippet of code to fully help.for ( i = 1; i <= steps; i++ ){var step(i) = global.get("step" + i);}What are you trying to do in that loop? What do you want out at the end?var step(i)... is not valid javascript, but without a better sense of what you're trying to do, its hard to suggest what it should be.
On 3 October 2017 at 20:06, Roger <rog...@qusax.eu> wrote:
global.set is working nice this waybut fighting now to load them in a loop like thisfor ( i = 1; i <= steps; i++ ){var step(i) = global.get("step" + i);}
cannot find out how to set the index i to the var stepX
tried +, . , [i]
Op dinsdag 3 oktober 2017 11:13:07 UTC+2 schreef Mark Setrem:
you can add dynamic content to the name of a global variable.e.g.global.set("name"+msg.topic,msg.payload);[{"id":"7f755270.8a6fc4","type":"inject","z":"68f1ee9d.501428","name":"","topic":"thetopic","payload":"test","payloadType":"str","repeat":"","crontab":"","once":false,"x":116.5,"y":134,"wires":[["d7b43898.7662c8"]]},{"id":"d7b43898.7662c8","type":"function","z":"68f1ee9d.501428","name":"set global","func":"\nglobal.set(\"name\"+msg.topic,msg.payload);\n\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":120,"wires":[[]]},{"id":"4b9211cd.50034","type":"inject","z":"68f1ee9d.501428","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":120,"y":200,"wires":[["f93661d8.0960a8"]]},{"id":"f93661d8.0960a8","type":"function","z":"68f1ee9d.501428","name":"get global","func":"\nmsg.payload = global.get(\"namethetopic\");\n\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":200,"wires":[["adb331f7.25bbe"]]},{"id":"adb331f7.25bbe","type":"debug","z":"68f1ee9d.501428","name":"","active":true,"console":"false","complete":"false","x":410,"y":200,"wires":[]}]
--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/9234c49e-0ea4-4614-86d7-ecb8fdb76d84%40googlegroups.com.
var stepCount = 5;
var stepArray = []; // start with an empty array
// array indexes start at 0
for (var i = 0; i < stepCount; i++) {
stepArray[i] = i + 1;
console.log("set step #" + stepArray[i]);
}
// now save the whole array to global context
global.set("MySteps", stepArray);// get the array of steps, or an empty array (if not found)
var steps = global.get("MySteps") || [];
for (var i = 0; i < steps.length; i++) {
node.send({payload: steps[i]}); // or do something else with each step
console.log("get step #" + steps[i]);
}
return null;