#json datastoring methods

1 messages · Page 1 of 1 (latest)

shut bloom
#

trying to store the players data into a json file. then load when the player joins. Saves and unload from memory (or variables file) when the playher leaves.

So far having massive issues bc of skill issues fr fr

#

if anyone can make it into a template-based kind of thing then uh oka that would be much appreciated

sinful pagoda
#

Alternatively, you could use yaml storage, load the files directly to memory. You'll need the skript-yaml plugin (which has examples on the wiki)

shut bloom
#

it is somehow worse documented than skjson

sinful pagoda
#

not the wiki

#

don't know why that sent three times, that was weird

shut bloom
# sinful pagoda don't know why that sent three times, that was weird

is saving like this not possible?

since i want all players data to be stored seperately

{
    "data": {
        "stats": {
            "bounty": 0,
            "experience": 0,
            "level": 1
        }
    },
    "profile": {
        "created_at": "25/07/2025",
        "last_ip": "127.0.0.1",
        "last_login": "25/07/2025 20:38:50",
        "last_played": "25/07/2025 20:39:05",
        "playtime": 443698
    }
}
#

mine works but then it stopped working after ;-;

gaunt gorge
shut bloom
#

it works now dw, the only issue im having is that the data keep resetting to the template lol

#

@gaunt gorge

gaunt gorge
#

you edit it

#

or

#

waiting like a tick

#

then saving it

shut bloom
#

its not waiting

#

do i need to make it wait a tick or something?

gaunt gorge
#

it might not be

#

writing fast enough

#

or smh

shut bloom
#
send "DATA BEFORE LOAD: %{player_data::%{_player}'s uuid%::data::stats::level}%" to console
delete {player_data::%{_player}'s uuid%::*}
set {_json} to json from file getDataFile({_player})
send "Loaded JSON: %{_json}%" to console # <-- DEBUG
map {_json} to {player_data::%{_player}'s uuid%::*}
send "DATA AFTER LOAD: %{player_data::%{_player}'s uuid%::data::stats::level}%" to console
#

the data obv isnt mapped before loading it

#

but after loading it

#

the data isnt mapped either

#

and then the join event checks for missing data

#

aka the entire thing from the server storage

#

so it writes the default value

gaunt gorge
#

i see..

shut bloom
#

i mean this is the correct syntax right??

#

map {_json} to {player_data::%{_player}'s uuid%::*}

gaunt gorge
#

also isn't it suppost to be map {_json::*} nvm

#

by chance

shut bloom
#

hm

#

idk lmao

gaunt gorge
#
            send {_mapped::b} to console```
#

is his example

shut bloom
#

i just did map {_json} to {player_data::%{_player}'s uuid%::*}

#

since its per player basis

gaunt gorge
#

then broadcast {_test::*}

#

to see what happens

shut bloom
#

k

#
function loadPlayerData(player: offline player):

    delete {player_data::%{_player}'s uuid%::*}
    set {_json} to json from file getDataFile({_player})
    map {_json} to {player_data::%{_player}'s uuid%::*}

    send "JSON STUFF: %{player_data::%{_player}'s uuid%::*}%" to {_player}
gaunt gorge
shut bloom
#

k

#

it dont output anything

gaunt gorge
#

so its the issue

#

from the file

#

set {_json} to json from file getDataFile({_player})

#

is your issue

shut bloom
#

here waht the save file looks like:

    "data": {
        "race": {
            "id_1": {
                "crystal_slot_1": "none",
                "crystal_slot_2": "none",
                "crystal_slot_3": "none",
                "obtained": true,
                "stage": 1
            },
            "id_2": {
                "crystal_slot_1": "none",
                "crystal_slot_2": "none",
                "crystal_slot_3": "none",
                "obtained": false,
                "stage": 1
            },
            "selected": 1
        },
        "stats": {
            "bounty": 0,
            "deaths": 0,
            "experience": 0,
            "kills": 0,
            "level": 1
        }
    },
    "profile": {
        "last_ip": "127.0.0.1",
        "last_played": "27/07/2025 00:06:28",
        "playtime": 503110
    }
}```
shut bloom
#

hm no ida

#

since this is the example they given:

map {_json} to {_mapped::*}
send {_mapped::b} to console
gaunt gorge
#

beucase in the wiki, they bind it to bind json file "plugins/Skript/playerdata/%player's uuid%.json" as "player-%player's uuid%"

#

so like skript-yaml, they save it as a ID

#

then get it from the ID thats saved in memory

#

if that makes any sense.

shut bloom
#
local function hasData(player: offline player) :: boolean:
    if json file getDataFile({_player}) exists:
        return true
    return false