[Technical Intermediate Coding] Problem w/ Catching level

Discussion in 'Plugin Development' started by Jaker232, Oct 28, 2011.

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

    Jaker232

    Eclipse is telling me the operator for + is undefined for the argument type(s) String, void. I have made the method so the sender, executes that void method, and catches the level that the player has in his configuration. My syntax is this:

    Code:java
    1.  
    2. player.sendMessage(ChatColor.RED + "Level: " + catchselfLevel());
    3.  


    Also, one more intermediate question. Can I add the Player player argument so the method looks like
    Code:java
    1.  
    2. public void catchselfLevel(Player player) {
    3. }
    4.  

    then I call the variable from the method's variable?
     
  2. Offline

    jblaske

    Void doesn't return a value, so you can't concatenate that to a string. If you want to display the level then i would change your catchselflevel() function to a string rather than void, and return the new level.
     
  3. Offline

    Jaker232

    I changed the public void into public boolean. Lol, but yours don't make any sense. Each method should have booleans, I think.
     
  4. Offline

    jblaske

    No, a function can return any type you want it to. If you are returning a level, then you want to either a) return a string of that new level, or be return an int of that new level and convert it to string for the message you are trying to send to the player.

    If you aren't certain, don't tell somebody they are wrong. It just makes you look arrogant and unteachable.
     
  5. Offline

    Jaker232

    It would catch the integer and say the level's number by adding it into the string.
     
  6. Offline

    jblaske

    I understand what you are trying to do, i'm telling you that neither void nor boolean will work for what you want.

    With it as a void, you will always get a compile error for trying to concatenate on a void.
    With a boolean you will be sending players messages like "Level: True" and "Level: False"
     
  7. Offline

    Jaker232

    D'oh. I'm so stupid at coding.
     
    r3Fuze likes this.
  8. Offline

    jblaske

    Na, its a learning process. Just keep an open mind and be willing to learn and you can go far.
     
  9. Offline

    emericask8ur

    Dude why do you say this then say your going to make a ultra huge amzing plugin.....no... just no.....
     
    r3Fuze likes this.
Thread Status:
Not open for further replies.

Share This Page