Solved if variable is greater than argument - not working

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

Wynandus

Member
Aug 23, 2017
15
0
0
24
So basicily when i go ingame and try to send some tokens to a friend of mine and i have enough balance it still says i don't... Anyone got a solution?

code_language.skript:
            if arg-1 is "send":
                if arg-2 is set:
                    if arg-3 is set:
                        if (arg-3 parsed as num) is set:
                            if {token.balance.%uuid of player%} is greater than arg-3:
                                message "{@prefix} {@token_send}" to player
                                message "{@prefix} {@token_sendreceived}" to arg-2
                                set {presend.%player%} to arg-3
                                set {send.amount.%player%} to {presend.%player%} parsed as integer
                                wait 5 ticks
                                remove {send.amount.%player%} from {token.balance.%uuid of player%}
                                add {send.amount.%player%} to {token.balance.%uuid of arg-2%}
                                wait 5 ticks
                                delete {send.amount.%player%}
                                stop
                            else:
                                message "{@prefix} {@token_insufficient_amount}" to player
                                stop
                        else:
                            message "{@prefix} {@token_onlyusenumbers}"
                            stop
                    else:
                        message "{@prefix} {@token_send_usage}"
                        stop
                if arg-2 is not set:
                    message "{@prefix} {@token_send_usage}"
                    stop
                stop
In game:
cb2cf02ccd.png
 
code_language.skript:
if (arg-3 parsed as num) is set:
    if {token.balance.%uuid of player%} is greater than arg-3:
Based on the first line there, im assuming arg-3 is not a number, since you are parsing it.
The second line is not parsed as a number therefor its checking if your variable is greater than whatever arg-3 is, im assuming a string.
 
code_language.skript:
if (arg-3 parsed as num) is set:
    if {token.balance.%uuid of player%} is greater than arg-3:
Based on the first line there, im assuming arg-3 is not a number, since you are parsing it.
The second line is not parsed as a number therefor its checking if your variable is greater than whatever arg-3 is, im assuming a string.
changed it, it still doesn't matter. arg-3 is a just a normal [<text>]
Updated code:
code_language.skript:
            if arg-1 is "send":
                if arg-2 is set:
                    if (arg-3 parsed as num) is set:
                        if {token.balance.%uuid of player%} is greater than arg-3:
                            message "{@prefix} {@token_send}" to player
                            message "{@prefix} {@token_sendreceived}" to arg-2
                            set {presend.%player%} to arg-3
                            set {send.amount.%player%} to {presend.%player%} parsed as integer
                            wait 5 ticks
                            remove {send.amount.%player%} from {token.balance.%uuid of player%}
                            add {send.amount.%player%} to {token.balance.%uuid of arg-2%}
                            wait 5 ticks
                            delete {send.amount.%player%}
                            stop
                        else:
                            message "{@prefix} {@token_insufficient_amount}" to player
                            stop
                    else:
                        message "{@prefix} {@token_onlyusenumbers}"
                        stop
 
assuming {token.balance.%uuid of player%} is a number, your condition says
if {number} is greater than "text":
so you need to parse arg-3 as a number
 
code_language.skript:
            if arg-1 is "send":
                if arg-2 is set:
                    if (arg-3 parsed as num) is set:
                        if {token.balance.%uuid of player%} is greater than arg-3:
                            message "{@prefix} {@token_send}" to player
                            message "{@prefix} {@token_sendreceived}" to arg-2
                            set {presend.%player%} to %arg-3% parsed as num
                            set {send.amount.%player%} to {presend.%player%} parsed as integer
                            wait 5 ticks
                            remove {send.amount.%player%} from {token.balance.%uuid of player%}
                            add {send.amount.%player%} to {token.balance.%uuid of arg-2%}
                            wait 5 ticks
                            delete {send.amount.%player%}
                            stop
                        else:
                            message "{@prefix} {@token_insufficient_amount}" to player
                            stop
                    else:
                        message "{@prefix} {@token_onlyusenumbers}"
                        stop
                if arg-2 is not set:
                    message "{@prefix} {@token_send_usage}"
                    stop
                stop
changed it still doesn't work could you just correct me please?
 
I'm glad this is solved, but I just want to help you out a bit here. instead of saying "greater than" just put >=
e. g.
code_language.skript:
if {token.balance.%uuid of player%} >= arg-3:
That way, if you had 50 tokens, you will be able to send it no matter what, and then you will have 0.
If it was....
code_language.skript:
if {token.balance.%uuid of player%} is greater than arg-3:
You will not be able to send the 50 tokens because you only have 50 tokens, nothing greater. You will need 51 tokens to send 50 tokens. Which doesn't make any sense to players.


Explaining the <>=

> stands for "greater than".
Comes in while writing a script, when you want to compare 2 numbers, any variable is useable too.
Let's say you set a variable called {money} to player's balance, and now you want to compare it to a shop's price you are making.

code_language.skript:
if {money} > 100:
    remove 100 from {money}
    give player 1 apple

< stands for "not greater than" or "less than"
Just the opposite of >

= stands for "equals"
It's recommended to use with < or > for better performance (gameplay wise).
Use the same example above
code_language.skript:
if {money} >= 100:
    remove 100 from {money}
    give player 1 apple
As you can see, >= now stands for "greater than" and "equals to"

I'm just trying to give you a better way of doing stuff. Hope you understand.
 
  • Like
Reactions: TPGamesNL
Status
Not open for further replies.