Solved Color on signs

Discussion in 'Plugin Development' started by Betagear, Oct 10, 2015.

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

    Betagear

    Hi.
    I'm trying to put color on my signs, with a variable that hold the colors. But for now, Eclipse tells me that there is a syntax error. Code :
    Code:
                    sign.setLine(2, BattleType(world));
                    ChatColor color;
                    if (worldplayers < MaxPlayers(world) / 4) {
                        color = ChatColor.BLUE;
                    }else if (worldplayers < MaxPlayers(world) / 2) {
                        color = ChatColor.DARK_GREEN;
                    }else if (worldplayers < MaxPlayers(world) / 4 *3) {
                        color = ChatColor.YELLOW;
                    }else {
                        color = ChatColor.RED;
                    }
                    sign.setLine(3, color worldplayers + "/" + MaxPlayers(world));
                    sign.update();
     
  2. Offline

    PDKnight

    It's because color (or ChatColor.something) is a string, so at line
    Code:java
    1. sign.setLine(3, color worldplayers +"/"+ MaxPlayers(world));

    you're not joining two strings, color and worldplayers, so you have to put + character between them :)

    Have a nice day
    PDKnight
     
    Last edited: Oct 10, 2015
  3. Offline

    teej107

    is it that? Maybe it'll help to show what error you have. It could be anything.
     
  4. Offline

    Betagear

    @PDKnight @teej107 It's not, if I do this it says :"The operator "+" is undefined for the arguments type(s) ChatColor, int".
     
  5. Offline

    PDKnight

    Hm, try to do
    Code:java
    1. sign.setLine(3, color + (worldplayers+"") +"/"+ MaxPlayers(world));
     
  6. Offline

    Betagear

  7. Offline

    mythbusterma

    @Betagear

    I don't really understand how that message is ambiguous at all.

    And it's really sloppy to do it that way. Use toString() on the ChatColor and it will work fine.

    @PDKnight

    No, ChatColors are not Strings, they are enums with a toString() method that is implicitly called by concatenating them with Strings. There is a difference.
     
  8. Offline

    Zombie_Striker

    @Betagear
    If you want to add different objects to the same piece of text, you need the + char. What you currently have is the object color and the object world players "mixing" into one.
     
  9. Offline

    PDKnight

Thread Status:
Not open for further replies.

Share This Page