Plugin Help Hashmap return null ?

Discussion in 'Plugin Help/Development/Requests' started by haussik, Jan 18, 2015.

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

    haussik

    Here's my code:
    Code:
    HashMap<String, Integer> player_life = new HashMap<String, Integer>();
    
    String player = event.getPlayer().getName();
    int life = 2;
    
    player_life.put(player, life);
    When i want the game to show me the message with player.sendMessage( player_life.get(player) + " / " + player_life.get(life) ); The game print: 2 / null.


    What's wrong ._. .. ?
     
  2. Offline

    pie_flavor

    .........That's not how hashmaps work. A HashMap is like a file system. The String is the name, the Integer is the file contents. Each key has only one value, but multiple keys have the same value. If you already have the variables player and life, why do you need to get them from the hashmap? Hashmaps are for saving for later usage. Also, if you have the player name, just write the key, then use the HashMap method for the other value.
     
  3. Offline

    haussik

    Ho thanks :) my bad
     
Thread Status:
Not open for further replies.

Share This Page