jabelar Posted May 10, 2014 Posted May 10, 2014 Okay, because I make my mods for my kids to use and because they can't always agree on how the mechanics should work I have a text file for configuring the mods. (I need to look at implementing mod options properly...). Anyway, in the dev environment it works fine -- I have text file in Configuration format and can change the properties of the game. In my published mod, the config file is found (based on canRead() method call returning true) but it doesn't seem to like the values because it returns the default values (which happen when it thinks the values aren't Boolean as expected). Here's my processConfig() method: protected void processConfig() { // might need to use suggestedConfigFile (event.getSuggestedConfigFile) location to publish System.out.println(WildAnimals.MODNAME+" config path = "+WildAnimals.configPath); WildAnimals.configFile = new File(WildAnimals.configPath); System.out.println("Config file exists = "+WildAnimals.configFile.canRead()); config = new Configuration(WildAnimals.configFile); WildAnimals.config = config; WildAnimals.configBigCatsAreManEaters = config.get(Configuration.CATEGORY_GENERAL, "BigCatsAreManEaters", true).getBoolean(true); System.out.println("Big cats are man eaters = "+WildAnimals.configBigCatsAreManEaters); WildAnimals.configIncludeSnakes = config.get(Configuration.CATEGORY_GENERAL, "IncludeSnakes", false).getBoolean(false); System.out.println("Include snakes = "+WildAnimals.configIncludeSnakes); WildAnimals.configIncludeBigCats = config.get(Configuration.CATEGORY_GENERAL, "IncludeBigCats", false).getBoolean(false); System.out.println("Include big cats = "+WildAnimals.configIncludeBigCats); WildAnimals.configIncludeHerdAnimals = config.get(Configuration.CATEGORY_GENERAL, "IncludeHerdAnimals", false).getBoolean(false); System.out.println("Include herd animals = "+WildAnimals.configIncludeHerdAnimals); } Here's the actual config file contents: # Configuration file #################### # general #################### general { B:BigCatsAreManEaters=false B:IncludeSnakes=true B:IncludeBigCats=true B:IncludeHerdAnimals=true } And here is console output of the published mod (note the returned values are the default ones): [19:20:37 INFO]: Client> WildAnimals+ config path = WildAnimals/src/assets/wildanimals/config/config.cfg [19:20:37 INFO]: Client> Config file exists = true [19:20:37 INFO]: Client> Big cats are man eaters = true [19:20:37 INFO]: Client> Include snakes = false [19:20:37 INFO]: Client> Include big cats = false [19:20:37 INFO]: Client> Include herd animals = false And here is console output in the development environment (the returned values match the config file values): WildAnimals+ config path = WildAnimals/src/assets/wildanimals/config/config.cfg Config file exists = true Big cats are man eaters = false Include snakes = true Include big cats = true Include herd animals = true In both cases it seems to find the file, so I am perplexed on why it would parse differently. Any ideas? Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
TheGreyGhost Posted May 10, 2014 Posted May 10, 2014 Hi My guess: it's finding a file, but not the one you think. When running the published mod, try renaming the file you think it is reading, and see if it complains. That might give you a clue. -TGG Quote
Parker8283 Posted May 10, 2014 Posted May 10, 2014 Your config file is not being placed in the correct directory. Where do you define the configPath variable? Could we see it? Quote
jabelar Posted May 10, 2014 Author Posted May 10, 2014 Okay, it seems that the code is creating the file prior to me testing if it is there -- I can see a new config.cfg file has appeared after I run the code. Does the new File() create an actual file? Or does the canRead() method only indicate that there is a logical file open and not a physical file? I thought (noob I guess) that the new File() was sort of a logical thing until you actually did file operations to create the physical file... And I thought that the canRead() was related to a physical file (because the description talks about file permissions from the file system)... Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
TheGreyGhost Posted May 10, 2014 Posted May 10, 2014 Hi This part in Configuration.load() creates the new file automatically if it doesn't already exist if (!file.exists() && !file.createNewFile()) { return; } -TGG Quote
delpi Posted May 10, 2014 Posted May 10, 2014 I gave you the long version below, but the short version is I think you are missing "config.load();" after you say "config = new Configuration(file);". Need something like this in your commonproxy new Config().load(); Something like this in your config file public class Config { // Setup Variables public Dimension_Manager instance = Dimension_Manager.instance; public static Configuration config; // Setup Specific Variables private String name = instance.modid + ".cfg"; private List<String> worlds = new ArrayList<String>(); private int world_num = 5; public Config() { } public void load() { // Create the folder String path = instance.path_config; // Try for the config file File file = new File(path + "/" + name); try { file.createNewFile(); } catch (IOException e) { } // Allocate the file to the config config = new Configuration(file); config.load(); // Determine player head drop config.addCustomCategoryComment("overall", "Overall Settings for Mod"); instance.properties().head_drop(config.get("overall", "overall.head_drop", true).getBoolean(true)); // Save the config config.save(); } } Compare with yours and see what to change. Quote Long time Bukkit & Forge Programmer Happy to try and help
jabelar Posted May 10, 2014 Author Posted May 10, 2014 I know that the actual problem is that the config file directory was in wrong place, so I know how to fix that. And I know that the Configuration class will create a file if it doesn't find one (I think that is bad programming practice, but whatever). But I was curious because my check for whether the file existed seem to pass when I'm pretty sure there wasn't such a file, and the check for the file comes before the Configuration is created. It's okay, I can fix the actual problem. I just like to understand when I find something unexpected. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
TheGreyGhost Posted May 10, 2014 Posted May 10, 2014 Hi I'm pretty sure you're right, just creating a File doesn't actually create it on disk until you ask it to (eg createNewFile()), likewise canRead() doesn't create it automatically either. -TGG Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.