If Variable is = or > than variable

  • 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 community!

    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.

GamingGeek

Supporter
Aug 1, 2017
46
0
0
Hi, I'm trying to make it so players can convert "karma" to money but I can't seem to get it to work

Here's my current code:
code_language.skript:
command /karma250:
    trigger:
        set {karma.required.%player%} to 250
        if {karma.%player%} is greater than {karma.required.%player%}:
            execute console command "/eco give %player% 100"
            add -250 to {karma.%player%}
            send "&a&lTransaction Complete!"
        else:
            send "&c&lTRANSACTION FAILED! KARMA NEEDS TO BE MORE THAN 250!"
(There's a GUI that makes a player execute /karma250 when an item is clicked)
but whenever I try to use the command, it gives me "&c&lTRANSACTION FAILED! KARMA NEEDS TO BE MORE THAN 250!" when {karma.%player%} is set to 1000000.
 
code_language.skript:
command /karma250:
    trigger:
        set {_karma} to 250
        {karma.%player%} is less than {_karma}:
            send "&cnot enough karma"
            stop
        execute console command "/eco give %player% 100"
        remove 250 from {karma.%player%}
        send "&acompleted"

I mean, that's the code. Most probably the player doesn't have 1 million karma when you execute the command.

Most of the time, if something like this happens the best you can do is output the variable contents somewhere to test what did go wrong. If it still doesn't work try to put message "%{karma.%player%}%" before the comparison

add -250 is equivalent to remove 250, too.
And don't ever create global variables when you only need local ones.
 
code_language.skript:
command /karma250:
    trigger:
        set {_karma} to 250
        {karma.%player%} is less than {_karma}:
            send "&cnot enough karma"
            stop
        execute console command "/eco give %player% 100"
        remove 250 from {karma.%player%}
        send "&acompleted"

I mean, that's the code. Most probably the player doesn't have 1 million karma when you execute the command.

Most of the time, if something like this happens the best you can do is output the variable contents somewhere to test what did go wrong. If it still doesn't work try to put message "%{karma.%player%}%" before the comparison

add -250 is equivalent to remove 250, too.
And don't ever create global variables when you only need local ones.

Thanks! The 1 million karma was just what I set my Karma to as an example.
 
Thanks! The 1 million karma was just what I set my Karma to as an example.

Yeah but even still, imagine the following scenario:
code_language.skript:
on command:
    set {karma.%player%} to 50

command /karma250:
    trigger:
        if {karma.%player%} is less than 250:
            message "error"

Never will karma250 not give an error. So thats why you have to make sure no other part of your code is modifying {karma.%player%} in any way that could cause this problem.
 
code_language.skript:
command /karma250:
    trigger:
        set {_karma} to 250
        {karma.%player%} is less than {_karma}:
            send "&cnot enough karma"
            stop
        execute console command "/eco give %player% 100"
        remove 250 from {karma.%player%}
        send "&acompleted"

I mean, that's the code. Most probably the player doesn't have 1 million karma when you execute the command.

Most of the time, if something like this happens the best you can do is output the variable contents somewhere to test what did go wrong. If it still doesn't work try to put message "%{karma.%player%}%" before the comparison

add -250 is equivalent to remove 250, too.
And don't ever create global variables when you only need local ones.
I just noticed that the 250 Karma isn't being removed from the player, any reasons why?
 
Quoting my last message...
Yeah but even still, imagine the following scenario:
code_language.skript:
on command:
    set {karma.%player%} to 50

command /karma250:
    trigger:
        if {karma.%player%} is less than 250:
            message "error"

Never will karma250 not give an error. So thats why you have to make sure no other part of your code is modifying {karma.%player%} in any way that could cause this problem.

Also I hope you're not doing this:
code_language.skript:
set {karma.%player%} to "250"

Because that's setting the variable to a text. And you can't remove a number from a text. You don't use quotes when setting variables to numbers.
 
Also I hope you're not doing this:
code_language.skript:
set {karma.%player%} to "250"

Because that's setting the variable to a text. And you can't remove a number from a text. You don't use quotes when setting variables to numbers.
You. Are. A. God. (And I'm an idiot) :emoji_stuck_out_tongue:
The skript is working perfectly now
 
Status
Not open for further replies.