#clear database

1 messages · Page 1 of 1 (latest)

frank star
#

that custom db constructor

lost pebble
frank star
#

idk what ur db constructor follows but if u use singleplayer dynamic property then u can clearDynamicProperty(?)

lost pebble
#

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];
    }
}
ember dune
#

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()

lost pebble
#

how to use it

raw dome
ember dune
lost pebble
#

i’m confused how to clear 1 player specified db?

ember dune
lost pebble
#

so just clearDynamicProperties()?

ember dune
lost pebble
#

not all only specificed

eager marlin
#

setDynamicProperty(id, undefined)

ember dune
#

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

high aspen
#

you can just leave it blank aswell

#
entity.setDynamicProperty('id')
ember dune
#

I can be wrong but can you be sure it can be left blank

high aspen
#

the value is optional

ember dune
#

ooo cool

lost pebble
high aspen
#

you said you wanted to clear only specified

#

dont use that

ember dune
lost pebble
#

nah

#

player.clearDynamicProperties()

#

it gave no errors tho

ember dune
#

ok I see i thought you didn't put that player lol

ember dune
#

Show the player variable

lost pebble
#

thru event

#

const player = event.sender

cunning fable
cunning fable
ember dune
#

Ofc it would

cunning fable
#

if he didnt get an error it means that player is defined riglt