Adding Data to sprites setData for array

I’m trying to modify some phaser 2 code to work with phaser 3 and am having an issue setting some data.

I have a sprite ‘tile’ that I set data for:

tile.setData({ row: x / _this.tileWidth, column: y / _this.tileHeight, words: {}, letter: letter, startWord: false});

This works fine but later in the code the Phaser 2 version adds a word and some properties to the words array in data(‘entry’ is an object):
tile.data.words[entry.word] = { orientation: entry.orientation, length: entry.word.length };

I’ve tried:
tile.setData.words[entry.word] = { orientation: entry.orientation, length: entry.word.length };

but get an error. Any insight into how I should do this?

tile.data.merge({
  row: x / _this.tileWidth,
  column: y / _this.tileHeight,
  words: {},
  letter: letter,
  startWord: false
});
// OR
tile.setData('row', x / _this.tileWidth);
// etc.

tile.getData('words')[entry.word] = {
  orientation: entry.orientation,
  length: entry.word.length
};

@samme

Your code is just getting the data from the words array though.

I’m not having a problem setting the data for row, column, etc. The problem I’m having adding data to the words array like the phaser 2 code is doing:

tile.data.words[entry.word] = { orientation: entry.orientation, length: entry.word.length };

this code is adding entry.word, orientation: entry.orientation, length: entry.word.length to the words array stored in data.

if it helps this is what the object looks like then it’s logged out:

tile.data.words[entry.word] = { orientation: entry.orientation, length: entry.word.length };

—>
console.log(tile.data.words);
gameboy: Object { orientation: “diagonal”, length: 7 }

In Phaser 3 sprite.data is a DataManager, not a plain object. You mustn’t set anything on tile.data, which is the manager. Use only tile.getData(), tile.setData(), or tile.data.values.

There are two ways to add properties to the words data value:

tile.getData('words')['name'] = {/* … */};

tile.data.values.words['name'] = {/* … */};

@samme The ‘tile.data’ code is the code from the Phaser 2 version I’m trying to duplicate. I tried:

tile.setData(‘words’)[entry.word] = {
orientation: entry.orientation,
length: entry.word.length
};

but then:

tile.getData(‘words’);

is undefined.

@samme I did just try:

tile.data.values.words[entry.word] = { orientation: entry.orientation, length: entry.word.length};

and i think it’s working.