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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    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.

Solved Duplicated Variables

Discussion in 'Skript' started by Mapzman, Dec 3, 2017.

Tags:
Thread Status:
Not open for further replies.
  1. Mapzman

    Mapzman Member

    Joined:
    Mar 26, 2017
    Messages:
    11
    Likes Received:
    0
    I'm curious if there is a solution to the duplicating of variables problem.

    For example, if {zombieKills.%player%} equals 0, then a moment later I add 1 to {zombieKills.%player%}, skript creates a second variable in the variables.csv file and I now have 2 {zombieKills.%player%} variables, one equal to 0 and one equal to 1.

    I'd like skript to change the value of the {zombieKills.%player%} variable itself, rather than creating a whole new variable.

    Thanks!
     
  2. drillzy

    drillzy Member

    Joined:
    Aug 6, 2017
    Messages:
    22
    Likes Received:
    0
    show some code so i can get the concept of what you are saying.
     
  3. Mapzman

    Mapzman Member

    Joined:
    Mar 26, 2017
    Messages:
    11
    Likes Received:
    0
    Code (Skript):
    1. on death of zombie:
    2.     if attacker is a player:
    3.         add 1 to {zombieKills.%attacker%}
    For every zombie a player kills, their {zombieKills.%attacker%} variable is increased by 1.

    If a new player joins my server, their {zombieKills.%attacker%} variable is equal to 0, and in the variables.csv file it shows:

    {zombieKills.%attacker%} = 0

    When the new player kills a zombie, their {zombieKills.%attacker%} variable is increased by 1, and in the variables.csv file it shows:

    {zombieKills.%attacker%} = 0
    {zombieKills.%attacker%} = 1

    Instead of increased the original {zombieKills.%attacker%} by 1, skript creates a whole new variable with 1 value more than the original, so for every zombie the player kills, a new variable is added to the variables.csv file, which is extremely inefficient
     
  4. drillzy

    drillzy Member

    Joined:
    Aug 6, 2017
    Messages:
    22
    Likes Received:
    0
    Did you make sure that when the new player joins, their variable gets set so it can be used? This is what you should do to use the current variable.

    Code (Text):
    1.  
    2. on join:
    3.     if {zombieKills.%player%} is not set:
    4.         set {zombieKills.%player%} to 0
    5.  
     
  5. Mapzman

    Mapzman Member

    Joined:
    Mar 26, 2017
    Messages:
    11
    Likes Received:
    0
    I'm sorry I made you confused, that isn't the problem I'm facing. I already set that event up. The problem is that there are too many variables being duplicated in the variables.csv file. Instead of overwriting old variables, skript creates new variables every time you want to change the original one.

    If you've ever programmed with Java, think of it as characters of a string. You can't edit the characters of a string, you can only create a copy of the string to take the original string's place. In skript, the {zombieKills.%player%} variable is not being changed, a new variable is being created to take the original {zombieKills.%player%} variable's place. But, unlike Java, the original {zombieKills.%player%} is not automatically deleted and so an extra, useless {zombieKills.%player%} variable is left in the variables.csv file. I want to know how, if there is a way, to force skript to automatically delete the extra {zombieKills.%player%} variable so there aren't duplicates of the same variable.
     
  6. drillzy

    drillzy Member

    Joined:
    Aug 6, 2017
    Messages:
    22
    Likes Received:
    0
    Yea, im not exactly sure on how to fix this. sorry.
     
  7. Mapzman

    Mapzman Member

    Joined:
    Mar 26, 2017
    Messages:
    11
    Likes Received:
    0
    Woops, I am an idiot, you can filter out duplicates in excel. Although, I still think skript should automatically do that. Thanks anyway!
     
  8. btk5h

    Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    154
    Likes Received:
    157
    Skript automatically cleans up the variables.csv when the server starts.

    Skript loads all variables into memory when the server starts. Skript only writes variables to the database in order to keep track of data between server reboots. If you're using a CSV flatfile for variable storage, Skript will append entries to the file because it's much faster than rewriting the entire file without duplicates.
     
    • Informative Informative x 1
Thread Status:
Not open for further replies.
Loading...