Most performant way to save data

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

sluhtie

Supporter
Feb 8, 2020
117
9
18
Germany
cwcodes.de
Hey, so I'm trying out for a while now what would be the most performant and efficient way to save player data.
I came up with 4 different ways to do so. But now I wanted to ask what you guys think is the best way to do that.
I sorted them from most performant to most unperformant.

Method 1 - String Variables

So my idea was to instead to have 1 variable for every different option of a player, to you 1 single variable named something like playerdata.
Here's an example:
code_language.skript:
#Instead of having this:
{coins::%uuiid of player%}
{tokens::%uuiid of player%}
{kills::%uuiid of player%}
{deaths::%uuiid of player%}

#To have this:
set {playerdata::%uuid of player%} to "coins:0|tokens:0|kills:0|deaths:0"

#And in order to get the Values use a custom function for example this one:
function getPlayerData(p: offline player, value: string) :: number:
    set {_data::*} to {playerdata::%uuid of {_p}%} split at "|"
    loop {_data::*}:
        loop-value contains {_value}
        set {_x} to loop-value
        replace all "coins:", "tokens:", "kills:" and "deaths:" with "" in {_x}
        return {_x} parsed as number

#And this to set:
function setPlayerData(p: offline player, cps: number, tokens: number, maxengines: number, kills: number, deaths: number, bb: number):
    set {playerdata::%uuid of {_p}%} to "cps:%{_cps}%|tokens:%{_tokens}%|maxengines:%{_maxengines}%|kills:%{_kills}%|deaths:%{_deaths}%|bb:%{_bb}%"


Method 2 - Player NBT instead of Variables
So my Idea was instead to use Variables, just use the NBT of a player to set different data. This allows you to replace nearly every variable with player NBT
Here's an example:
code_language.skript:
#Get values
function getFromNBT(p: offline player, value: string) :: number:
    return tag {_value} of nbt of player

#Set values
function setNBT(p: offline player, value: string, amount: number):
    set tag {_value} of nbt of player to "%{_amount}%"


Method 3 - List Variables
The probably most known way is to use list variables, this means instead of using a dot to seperate variables, to use a double colon.
Here's an example:
code_language.skript:
#Instead of this:
set {coins.%uuid of player%} to 100

#Use this:
set {coins::%uuid of player%} to 100


Method 4 - MYSQL Storage
Well known method of storing data in a database running on Server externally from skript.
All through the most unpermormant way because it takes a long time to transfer data into a database such as getting data from it. So it's not that fast aswell..

So those are my methods that I got for storing data. If you know any other way to store data let me know. Also please don't blame me for my english, this was very quickly written without minding grammar sry.

Regards, sluhtie
 
Last edited:
Status
Not open for further replies.