How do you add an int to a sign?

Discussion in 'Plugin Development' started by Gamesareme, Aug 5, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Gamesareme

    I am trying to make so when a player clicks a sign, a number on it will change. I am trying to set a number on the sign, but I am only able to set a string. So if I make a string like this "1" I get the number on the sign, but I need to be able to update this. Like getting the line it is on get the int add one to it and then update the sign. I have not been able to do this though, because the sign only works with strings. Is there something I am missing about signs?
     
  2. Offline

    Dragonphase

    Gamesareme

    Code:java
    1. int number = Integer.parseInt(lineFromSign);


    It will throw a NumberFormatException if your String is not a number. The best way to avoid this is by checking if it is actually a number:

    Code:java
    1. public boolean isInteger(String string){
    2. try{
    3. Integer.parseInt(string);
    4. }catch(Exception ex){
    5. return false;
    6. }
    7.  
    8. return true;
    9. }
     
  3. Offline

    Gater12

    Gamesareme
    Integer#parseInt(String s)

    Be sure to properly handle it if in a situation that a String received is not "garuanteed".
     
Thread Status:
Not open for further replies.

Share This Page