Hi everyone,
first timer here, very sorry to bother you. Have been reading and trying to get around on my own for hours now, but I really can not solve/implement how to store an array with global.set and read it back in next time my function node is called. I have searched and read dozens of forum threads and started to learn about reference vs copy (I understand that global.get gives me a reference to the array), but nevertheless I am unable to solve how to store and retrieve an array of objects.
This is just my last variation, which has gives me 0 objects everytime once called:
var ind_data={};
ind_data.nodeid=msg.nodeId;
ind_data.type=msg.type;
ind_data.payload=msg.payload;
var stored_individual_data=global.get("global_invidual_data")||[];
msg.global_individual_data_orig=stored_individual_data.length;
msg.ind_data=ind_data;
stored_individual_data.push(ind_data);
global.set("global_individual_data",stored_individual_data);
msg.global_individual_data_post=stored_individual_data.length;
return msg;
We have all been there with typos. The brain knows what you meant to type so doesn't even bother reading it.
Of course one moral might be not to use complex variable names that take a lot of typing, and in particular words like individual which I think are prone to typos. However it is also important not to go the other extreme and use three letter meaningless names.
I will always remember taking over some code when I worked on a system monitoring car systems. The code had a variable todo and I wondered for ages why it was named that. It wasn't till I came to look back at it much later that I realised it was total odometer!