Solved Duplicated Variables

  • 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.

Mapzman

Member
Mar 26, 2017
11
0
1
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!
 
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!
show some code so i can get the concept of what you are saying.
 
code_language.skript:
on death of zombie:
    if attacker is a player:
        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
 
code_language.skript:
on death of zombie:
    if attacker is a player:
        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
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:
on join:
    if {zombieKills.%player%} is not set:
        set {zombieKills.%player%} to 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.
 
Woops, I am an idiot, you can filter out duplicates in excel. Although, I still think skript should automatically do that. Thanks anyway!
 
Woops, I am an idiot, you can filter out duplicates in excel. Although, I still think skript should automatically do that. Thanks anyway!
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.
 
Status
Not open for further replies.