Can a `change` node access a globaI variable if it's an array?

I'm trying to build a remote tic-tac-toe game with my grandson. I'm storing the 'board' in a global array 'board' as a 3x3 array

var b = [[9,9,9],[9,9,9],[9,9,9]]
global.set("board",b)

The board is a set of buttons and each button sends a payload like this for r0,c0 {"r":0,"c":0}
What I want to do in a change node is set global.board[0][0] to a number but if I use
global.board[msg.payload.r][msg.payload.c] I get an error.

Is there a way to achieve this?

If i use global.board[0][0] it works, using a message property like global.board[msg.array.x][msg.array.y] doesnt work for me either. Maybe use a function node in this case. It will work there probably.

Yup I've already swapped to using a function but I'd still like to know if it is doable.

This is what I did in the function node

var r = msg.payload.r
var c = msg.payload.c
var b = global.get("board")
b[r][c] = 2
global.set("board",b)
return msg
1 Like

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