Problem with array persistence with global.get / global.set

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;

Anyone can help me out?
Thanks very much,

Joost

10/25/2020, 7:22:44 PMnode: 97bf2754.81864
Node 130 Voltage : msg : Object
object
payload: "3.46"
port: "/dev/ttyUSB0"
_msgid: "dc734303.014eb"
nodeId: 130
childSensorId: 9
messageType: 1
ack: 0
subType: 24
origin: 1
messageTypeStr: "C_SET"
subTypeStr: "V_VAR1"
topic: "Node 130 Voltage"
type: "volt"
timestampJC: "19:22"
nodeId_array: array[5]
global_individual_data_orig: 0
ind_data: object
global_individual_data_post: 2

Spot the diliberate spelling mistake

global_invidual_data
global_individual_data

Omg omg omg omg omg omg omg
I am working on this problem for hours now. This can't be true. omg omg omg

Off to try things out just now, will get back.

(screaming)

1 Like

Not sure if I'm happy it's working now (it is)or devastated I spent so much time on this...

Thank you very much for thinking/reading this through, supposedly I'd have never spotted that!

Joost

Gotta love this forum... ! Thanks @Steve-Mcl

1 Like

lol

If it makes you feel any better, it took me nearly 10 seconds to spot it. :smiley: :stuck_out_tongue:

its easy to get bogged down in the detail.

1 Like

The moral of the story, always check for typo's

The moral of the story always check for typo's

:smile: Ok will do

Thanks everyone, have a great day/night

2 Likes

You are improving, see only 3 minutes this time.

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!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.