Issues with subtracting from 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.

Ceravia

Member
Apr 17, 2017
18
0
0
26
code_language.skript:
command /crate [<text>] [<text>]:
    trigger:
        if player's world is not "world":
            message "&aYou must open crates from the hub!"
        else:
            if arg-1 is not set:
                teleport player to location -19, 82, 56 in "world" parsed as world
                message "&aClick a chest to purchase, or open crates!"
            else:
                if arg-1 is "buy":
                    message "Click here to buy crates on our store!"
                else:
                    if arg-1 is "open":
                        if arg-2 is not set:
                            message "&aPlease use &6/crate open common &aor &6/crate open legendary"
                        else:
                            if arg-2 is "common":
                                wait 1 tick
                                set {crate.common.%player%} to value "Common" get of "plugins/crate/%player%.yml"
                                if {crate.common.%player%} parsed as integer > 0:
                                    remove 1 from {crate.common.%player%}
                                    set "Common" to "%{crate.common.%player%}%" in yaml file "plugins/crate/%player%.yml"
                                    broadcast "%{crate.common.%player%}%"
                                    set {chest.perm} to random element out of {common::reward::*}
                                else:
                                    message "&cYou do not have a crate!"



Alright so nothing is subtracting. Also, set {crate.common.%player%} to {crate.common.%player%} - 1 just sets the value to -1, not the value -1. Very frusterated with this, haven't found a fix in over 2 hours. Using v8 fixes, nothing else lets my other skripts work properly. All of my other skripts allow values to be subtracted using "remove" as well as "set {var} to {var}-1. Any suggestins on how I can fix this?
 
Parse it as an integer when you get the value from the YML file. You're receiving the value as a string but then are treating it as a number, even if the value you retrieve is "5", saying 'remove 1 from "5"' makes as little sense as saying 'remove 1 from "potato"'. It's a string so you can't "remove" a number from it.
 
Parse it as an integer when you get the value from the YML file. You're receiving the value as a string but then are treating it as a number, even if the value you retrieve is "5", saying 'remove 1 from "5"' makes as little sense as saying 'remove 1 from "potato"'. It's a string so you can't "remove" a number from it.
THANK YOU SO MUCH IT MAKES SENSE AND IT WORKS I LOVE YOU
 
I know this is solved but I'll give you some suggestions:
1. You don't have to do an else and then an if statement for check everything, the else if is a thing. So, instead of what you're doing right now you could do:
code_language.skript:
if player's world isn't "spawn":
    send "whatever"
    if arg-1 is "buy":
        #stuff here
    else if arg-1 is "open":
        #more stuff here
There is also a better way to do so if you have MundoSK and it's using switches/matches. Example:
code_language.skript:
if player's world isn't "spawn":
    send "whatever"
    switch arg-1:
        case "buy":
            #stuff here
        case "open":
            #more stuff here
2. Don't use WildSkript, for the love of God, it's an ancient and unsupported addon. Preferably, I would use skUtilities for file-related stuff.
3. Use local/temporary variables, there is no point on use a global variable when you're going to use it only once in that trigger.
 
I know this is solved but I'll give you some suggestions:
1. You don't have to do an else and then an if statement for check everything, the else if is a thing. So, instead of what you're doing right now you could do:
code_language.skript:
if player's world isn't "spawn":
    send "whatever"
    if arg-1 is "buy":
        #stuff here
    else if arg-1 is "open":
        #more stuff here
There is also a better way to do so if you have MundoSK and it's using switches/matches. Example:
code_language.skript:
if player's world isn't "spawn":
    send "whatever"
    switch arg-1:
        case "buy":
            #stuff here
        case "open":
            #more stuff here
2. Don't use WildSkript, for the love of God, it's an ancient and unsupported addon. Preferably, I would use skUtilities for file-related stuff.
3. Use local/temporary variables, there is no point on use a global variable when you're going to use it only once in that trigger.

Thanks for the suggestions, time to learn skUtillities then. Thanks for telling me because I never really used yml much before this.

Also temporary variables are written like {_variable}, I think?
 
Status
Not open for further replies.