lapis readonly

I'm trying to create a wrapper function that simplifies reading and writing player data. However, I'm encountering an error that says: "attempt to modify readonly table." Lapis is returning the data as a readonly table, so I need a way to safely create a mutable copy of this data, modify it, and then send it back to be written. How can I do this properly?
public withReadData(updater: (data: PlayerData) => PlayerData): void {
const current = this.readData();
const mutableData // make mutable data here somehow?
const updated = updater(current);
this.writeData(updated);
}
public withReadData(updater: (data: PlayerData) => PlayerData): void {
const current = this.readData();
const mutableData // make mutable data here somehow?
const updated = updater(current);
this.writeData(updated);
}
playerEntity.withReadData((data) => {
data.inventory.items.push(blah);
return data;
});
playerEntity.withReadData((data) => {
data.inventory.items.push(blah);
return data;
});
Sorry if this is a silly question.
3 Replies
glenacus
glenacusOP3mo ago
I guess I can make a deep clone of data.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
glenacus
glenacusOP3mo ago
just document.read() and returns it The ts version of lapis read returns a Readonly<T>

Did you find this page helpful?