#clear database
1 messages · Page 1 of 1 (latest)
wym
idk what ur db constructor follows but if u use singleplayer dynamic property then u can clearDynamicProperty(?)
export class Database {
static info = {
end: "_DBS",
values: "_vl"
}
constructor(name) {
this.name = name;
this.MEMORY = {};
this.dataVL = world.getDynamicProperty(this.name + Database.info.end + Database.info.values) || 1;
this.init();
}
init() {
let data = Array.from({ length: this.dataVL }, (_, i) => world.getDynamicProperty(this.name + Database.info.end + "_" + i) || "{}").join("");
this.MEMORY = JSON.parse(data);
}
save() {
const parsed = chunkString(JSON.stringify(this.MEMORY), max_values);
let index = 0;
parsed.forEach((item) => {
world.setDynamicProperty(this.name + Database.info.end + "_" + index, item);
index++;
});
world.setDynamicProperty(this.name + Database.info.end + Database.info.values, parsed.length);
this.dataVL = parsed.length;
}
set(key, value) {
this.MEMORY[key] = value;
this.save();
}
get(key) {
return this.MEMORY[key];
}
}
if your doing:
for (const player of world.getAllPlayers()) {
player.clearDynamicProperties()
}
Then it will remove for all players
/**
* @param {string} playerName
* @returns {Player}
*/
function getPlayerByName(playerName) {
return Array.from(world.getPlayers()).find((player) => player.name === playerName);
}```
And yeah you get the player by name, then do clearDynamicProperties()
how to use it
why not getPlayers({ name: playerName })[0]?
oh lol i see
i’m confused how to clear 1 player specified db?
I just said
^
so just clearDynamicProperties()?
You want to clear all of the dynamic properties stored on that player right?
not all only specificed
setDynamicProperty(id, undefined)
Yeah 👆
If you want to clear all, then clearDynamicProperties() and if you want to clear only specified, then player.setDynamicProperty("id", undefined)
or setting it to null also works
Really? Never tried.
I can be wrong but can you be sure it can be left blank
it can.
the value is optional
ooo cool
I tried using
.clearDynamicProperties() but it didn’t work
So.... just .clearDynamicProperties()?
ok I see i thought you didn't put that player lol
And how you get that player?
Show the player variable
No errors ≠ Its working
why does that matter
Ofc it would
if he didnt get an error it means that player is defined riglt