Sorry if I sound like I don't know what I'm talking about, but anyways. I'm trying to change the value of bricks in my save file and for some reason it can't read the information.
public void addRecords(int brick, int log, int stone, int house){ x.format("%s%s\n%s%s\n%s%s\n%s%s", "brick", " "+brick, "log", " " +log, "stone", " "+stone, "house", " "+house); }
This writes information to my files. ^
public void addResource(String resource, int amount){ openFile(); readfile check = new readfile(); switch(resource){ case "brick": brick = check.readResource("brick"); System.out.println("original brick: " + brick); brick = brick + amount; System.out.println("after math" + brick); break; addRecords(brick, log, stone, house); closeFile(); }
In my case "brick", It doesn't set the value when I try to read it. Here is the readResource method.
public int readResource(String resource){ System.out.println("Looking for " + resource); String res = resource; openFile(); while(x.hasNext()){ String a = x.next(); String b = x.next(); if( a.equals(res)){ closeFile(); int c = Integer.parseInt(b); return c; } if(x.hasNext() == false){ closeFile(); System.out.println("Resource not found."); } } return 0; }
If anybody could help explain this to me I would appreciate it.
Short version:
This doesn't set brick to any value.brick = check.readResource("brick");