1. 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!


    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Most performant way to save data

Discussion in 'Skript' started by sluhtie, Jun 7, 2022.

Thread Status:
Not open for further replies.
  1. sluhtie


    Feb 8, 2020
    Likes Received:
    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 (Skript):
    1. #Instead of having this:
    2. {coins::%uuiid of player%}
    3. {tokens::%uuiid of player%}
    4. {kills::%uuiid of player%}
    5. {deaths::%uuiid of player%}
    7. #To have this:
    8. set {playerdata::%uuid of player%} to "coins:0|tokens:0|kills:0|deaths:0"
    10. #And in order to get the Values use a custom function for example this one:
    11. function getPlayerData(p: offline player, value: string) :: number:
    12.     set {_data::*} to {playerdata::%uuid of {_p}%} split at "|"
    13.     loop {_data::*}:
    14.         loop-value contains {_value}
    15.         set {_x} to loop-value
    16.         replace all "coins:", "tokens:", "kills:" and "deaths:" with "" in {_x}
    17.         return {_x} parsed as number
    19. #And this to set:
    20. function setPlayerData(p: offline player, cps: number, tokens: number, maxengines: number, kills: number, deaths: number, bb: number):
    21.     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 (Skript):
    1. #Get values
    2. function getFromNBT(p: offline player, value: string) :: number:
    3.     return tag {_value} of nbt of player
    5. #Set values
    6. function setNBT(p: offline player, value: string, amount: number):
    7.     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 (Skript):
    1. #Instead of this:
    2. set {coins.%uuid of player%} to 100
    4. #Use this:
    5. 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
    #1 sluhtie, Jun 7, 2022
    Last edited: Jun 7, 2022
Thread Status:
Not open for further replies.

Share This Page