How to make a variable parsed a number

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

Giuliox_Sniper

New Member
Nov 26, 2023
7
0
1
19
Hi. How do I make the variable {sc2} MUST a number?
Code:
on anvil gui click:
    if event-integer is 2:
        if title of event-anvil gui is "&lPrezzo":
            close player's inventory
            set {sc2} to event-text
            set {_sanvil3} to a new anvil gui named "&lProdotti" with default text "&f"
            open anvil gui {_sanvil3} to player
            
on anvil gui click:
    if event-integer is 2:
        if title of event-anvil gui is "&lProdotti":
            close player's inventory
            set {sc3} to event-text
            give 1 paper named "&2Scontrino" with lore "&r&7Cassiere: &r&e%player%", "&r&7Cliente: &r&e%{sc1}%","&r&7Prezzo: &r&e%{sc2}%","&r&7Prodotti: &r&e%{sc3}%" to player
 
You should be able to just do if {sc2} is a number
 
You could also do
code_language.skript:
set {sc2} to event-text parsed as number
on line 5. Similar thing on line 13.

Edit: It's a bit more common to do it this way. Keep in mind, though, that if event-text isn't a number, it'll return <none> after parsing. If it's guaranteed to be a number, go with this method. If you're not sure if it's a number or not (perhaps for user inputs or something like that), go with BaeFell's suggestion.
 
Last edited:
You should be able to just do if {sc2} is a number
This variable not working if i typed for example "100"




YAML:
on anvil gui click:
    if event-integer is 2:
        if title of event-anvil gui is "&lProdotti":
            close player's inventory
            set {sc3} to event-text
            if {sc2} is a number:
                if {bilancio:%player%} >= {sc2}:
                    remove {sc2} from {bilancio::%player%}
                    give 2 paper named "&2Scontrino" with lore "&r&7Cassiere: &r&e%player%", "&r&7Cliente: &r&e%{sc1}%", "&r&7Prezzo: &r&e%{sc2}%", "&r&7Prodotti: &r&e%{sc3}%" to player
                else:
                    send "&cNon hai abbastanza soldi!" to player
             else:
                 send "&cInserisci un numero!" to player
 
Last edited:
This variable not working if i typed for example "100"




YAML:
on anvil gui click:
    if event-integer is 2:
        if title of event-anvil gui is "&lProdotti":
            close player's inventory
            set {sc3} to event-text
            if {sc2} is a number:
                if {bilancio:%player%} >= {sc2}:
                    remove {sc2} from {bilancio::%player%}
                    give 2 paper named "&2Scontrino" with lore "&r&7Cassiere: &r&e%player%", "&r&7Cliente: &r&e%{sc1}%", "&r&7Prezzo: &r&e%{sc2}%", "&r&7Prodotti: &r&e%{sc3}%" to player
                else:
                    send "&cNon hai abbastanza soldi!" to player
             else:
                 send "&cInserisci un numero!" to player
Yeah, because "100" is a text if it got it from chat or any other type of text input, not a number, despite looking like one. Try what I said.
 
Please You can wrote the code for me?? I do not understand what you mean, because this is an input, where the players have to write an event-text, I want that if the event-text of the anvil gui is a number, then a paper is given to the player, otherwise nothing
Yeah, because "100" is a text if it got it from chat or any other type of text input, not a number, despite looking like one. Try what I said.
 
Please You can wrote the code for me?? I do not understand what you mean, because this is an input, where the players have to write an event-text, I want that if the event-text of the anvil gui is a number, then a paper is given to the player, otherwise nothing
I gave you the line as my first response to this thread:
code_language.skript:
set {sc2} to event-text parsed as number
and to do the same with {sc3}.
 
Thanks! But Why if {sc2} is number don't remove {sc2} from {bilancio::%player%}???:


code_language.skript:
on anvil gui click:
    if event-integer is 2:
        if title of event-anvil gui is "&lProdotti":
            close player's inventory
            set {sc3} to event-text
            if {sc2} is a number:
                remove {sc2} from {bilancio::%player%} #<----------
I gave you the line as my first response to this thread:
code_language.skript:
set {sc2} to event-text parsed as number
and to do the same with {sc3}.
 
Thanks! But Why if {sc2} is number don't remove {sc2} from {bilancio::%player%}???:


code_language.skript:
on anvil gui click:
    if event-integer is 2:
        if title of event-anvil gui is "&lProdotti":
            close player's inventory
            set {sc3} to event-text
            if {sc2} is a number:
                remove {sc2} from {bilancio::%player%} #<----------

I had to translate your code because I wasn't entirely sure what Prodotti or Prezzo meant, but now I understand a bit more.

Use this:
code_language.skript:
on anvil gui click:
    if event-integer is 2:
        if title of event-anvil gui is "&lProdotti":
            close player's inventory
            set {sc3} to event-text
            set {sc2} to {sc2} parsed as number # {sc2} is still considered a text because it came from a text input
            if {sc2} is set: # if {sc2} isn't a number, it'll return <none>
                remove {sc2} from {bilancio::%player%} # now that {sc2} has been parsed as a number, it should work

If {sc2} is meant to mark the price of a player-specific selection, though, I would recommend making it a list, using players as the indices, like you did with {bilancio::%player%}, just incase two people try to buy something at the same time.
 
Okay, thanks you
I had to translate your code because I wasn't entirely sure what Prodotti or Prezzo meant, but now I understand a bit more.

Use this:
code_language.skript:
on anvil gui click:
    if event-integer is 2:
        if title of event-anvil gui is "&lProdotti":
            close player's inventory
            set {sc3} to event-text
            set {sc2} to {sc2} parsed as number # {sc2} is still considered a text because it came from a text input
            if {sc2} is set: # if {sc2} isn't a number, it'll return <none>
                remove {sc2} from {bilancio::%player%} # now that {sc2} has been parsed as a number, it should work

If {sc2} is meant to mark the price of a player-specific selection, though, I would recommend making it a list, using players as the indices, like you did with {bilancio::%player%}, just incase two people try to buy something at the same time.