Solved Scoreboard below name turns always 0

Discussion in 'Plugin Development' started by sirantony, Jun 10, 2014.

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

    sirantony

    Hey,

    I can't get scoreboards to work, the BELOW_NAME though. It show always 0, despite the fact I put 100, or 50 (it's a custom objective). The SIDE_BAR works perfectly...

    How do I do this?

    (saw that getScore(offlineplayer) was deprecated, but I used it and it didn't work too)

    Thanks in advance!
     
  2. Offline

    Garris0n

    Post the code you're using.
     
  3. Offline

    sirantony

    Here ya go!

    Code:java
    1. Scoreboard sb = ...;
    2. Objective obj = sb.registerNewObjective("pc","pc");
    3. obj.setDisplaySlot(BELOW_NAME);
    4. obj.setDisplayName("%");
    5. Score s = obj.getScore(nameofplayer);
    6. s.setScore(100);
    7.  
    8. p.setScoreboard(sb);
     
  4. Offline

    Garris0n

    Well there's not exactly anything wrong with that. How are you calling it? Are you setting the score again anywhere else?
     
  5. Offline

    sirantony

    Nothing more, just this...
     
  6. Offline

    Garris0n

  7. Offline

    sirantony

    @Garris0n
    hmh, gotta test that one xD. Stay stand-by plz
     
  8. Offline

    Garris0n

    Use the 'tahg' button :p
     
  9. Offline

    sirantony

    @Garris0n
    Nope, still 0, one weird thing. The scoreboard doesn't appear on the player who typed the command, but at the other players...
     
  10. Offline

    Garris0n

    Well, they wouldn't see it if it's below name. They can't see their name.

    Anyway, current code being used? In the original code you only add one player.
     
  11. Offline

    sirantony

    @Garris0n,
    Well, no I have two clients, here's the code:

    Code:java
    1. Scoreboard sb = BattleField.pl().sm.getNewScoreboard();
    2. Objective obj = sb.registerNewObjective("test", "dummy");
    3. obj.setDisplayName("%");
    4. obj.setDisplaySlot(DisplaySlot.BELOW_NAME);
    5.  
    6. obj.getScore(p.getName()).setScore(100);
    7. p.setScoreboard(sb);


    @Garris0n,

    I got an update, I got it to work, with a global scoreboard. But then my sideboard is messed up...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  12. Offline

    Garris0n

    What is "a global scoreboard"?

    Also,
    Edit: You are saving the instance of the board somewhere, right?
     
  13. Offline

    sirantony

    Garris0n

    So, global scoreboard is the same scoreboard for everyplayer

    And ofcourse I save the instance. Im tryin something new, a bit of a hack, I'll send you if it worked.
     
  14. Offline

    Garris0n

    I really can't tell you what to fix without seeing the actual code. You're not posting the full code (as in the actual entire class and any class that calls its methods).
     
  15. Offline

    sirantony

    Garris0n
    It's that, beleive me or not.
    But I fixed it to let it work with multiple scoreboards. Basically when you set a below name scoreboard, it's for everyplayer except yourself, so when I set the scoreboard of player A and I want seeing the health of player B, then I have to change the scoreboard for player A with the name of player B.

    I gotta post this info somewhere...
     
  16. Offline

    Garris0n

    If that is it, you're not saving the instance of the scoreboard, and that might be causing problems.
     
  17. Offline

    sirantony

    Garris0n
    I'm saving the instances, I'm a java programmer, I know for sure how those things work...

    Anyway, thanks!
     
  18. Offline

    Garris0n

    So you have an instance variable that holds the scoreboard and I just can't see it? ...which means that is not the full code?
     
  19. Offline

    sirantony

    *facepalm* It's working, I fixed it and I saved the scoreboard in the class as a property.
     
Thread Status:
Not open for further replies.

Share This Page