Prevent Setting Variables To Letters/Words?

Discussion in 'Skript' started by iTommy, Jun 10, 2018.

Thread Status:
Not open for further replies.
  1. Hello, I'm currently making a Skript and in this Skript, the player typing a command will be able to set a variable to a number, problem is I would like to make it so they aren't able to set the variable to a letter/word. I tried this and it did not work.

    Code (Text):
    if arg 2 is a number:
      set {variable} to "%arg 2%"
    else:
      send "&cYou can only use digits."
    Anyone know how I can make this work? :p
     
  2. Use "<integer>" as your argument in your skript. For example:
    Code (YAML):
    command /mycmd <integer>:
        trigger
    :
           if "%arg-1%" is "1":
               send "One!"
           else
    :
               send "Please use 1 only!"
     
  3. OP wants to know if argument contains numbers only not specific numbers
    My answer would be not contextual but in java we do it like this using regex.
    if (argument[1].matches("[0-9]+") {
    int var = Integer.valueof(argument[1]);
    }
    check the Skript support site if the language supports regex and how to implement it
     
  4. Not looking for specific numbers, but <integer> will work, thanks. :)
    I'll look into it later, thanks. :)
     
Thread Status:
Not open for further replies.