user3507319
user3507319

Reputation: 1

Utilizing a Map properly

I'm new to Java, but learning quite well and been reading and understanding newer and better ways of Java.

Currently my issue right now is with using Map storing. As seen below this is how I'm storing the information in my class.

public Map<String , Object> req = new HashMap<String, Object>();

public void putReq() {  
   req.put("npcKills", 0); 
}

I'm looking for help on adding the stored variable to a saving script I'm using. Here's a regular usage of another save I'm currently using.

characterfile.write("logsCut = ", 0, 10);
characterfile.write(Integer.toString(Player.logsCut), 0, Integer.toString(Player.logsCut).length());
characterfile.newLine();

As you can see I want to implement my "npcKills" variable to the save script, just not entirely sure on how it's supposed to go. uses BufferedWritter btw

I'm also looking to find a addition to the value on demand so normally my int incrementing would be p.npcKills += 1;

I want to do that, but using the map.

Upvotes: 0

Views: 61

Answers (1)

EDToaster
EDToaster

Reputation: 3180

You can use

map.get("npcKills"); 

To get the values of the stored variables

To increment each value, you would have to do

map.put("npcKills", map.get("npcKills") + 1);

There is no easy way to increment the values

Upvotes: 2

Related Questions