Jump to content

Forge 1236 - Config Comments Unexpected Behavior


Draco18s

Recommended Posts

Not sure if a bug or Working as Intended (but in an unexpected manner).

 

So I was setting up the configs for a mod I'm working on and figured out I needed to comment a few settings.  So I added comments, similar to how Test1 is set up below.  The comment wasn't saving and no amount of config.save() calls in and around the line would cause it to do so.  The only way I could get it to save was to save the Property to a variable (Test 2).

 

    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
    	Configuration config = new Configuration(event.getSuggestedConfigurationFile());
    	
    	boolean configBool;
    	int configInt;
    	
    	/*Test 1*/
    	configBool = config.get("Test1", "boolTest", false).getBoolean();
        config.get("Test1", "intTest", 6).comment = "This is a comment on intTest for test 1.\nIt has several lines of comment to avoid text wrap and will not show up in the config file.\nMin 1, Max 12, Default 6.";
        configInt = Math.min(Math.max(config.get("Test1", "intTest", 6).getInt(), 1), 12);
    	
        /*Test 2*/
    	configBool = config.get("Test2", "boolTest", false).getBoolean();
        Property prop = config.get("Test2", "intTest", 6);
        prop.comment = "This is a comment on intTest for test 2.\nIt has several lines of comment to avoid text wrap and will show up in the config file.\nMin 1, Max 12, Default 6.";
        configInt = Math.min(Math.max(prop.getInt(), 1), 12);
    	config.save();
    }

 

And the resulting config file generated:

 

# Configuration file

test1 {
    B:boolTest=false
    I:intTest=6
}


test2 {
    B:boolTest=false

    # This is a comment on intTest for test 2.
    # It has several lines of comment to avoid text wrap and will show up in the config file.
    # Min 1, Max 12, Default 6.
    I:intTest=6
}

 

I realize that Test 2 is better practice (due to caching the Property instead of calling get() twice) but it seems to me that both methods should save the comment to the file, yet the former does not.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Ah!  I didn't see that there was a comment-passed version.  That makes so much more sense.

 

The JavaDoc window that pops up auto-complete suggestions is not very wide, so anything beyond "string name" gets cut off and I've been using that particular getter for a while now (easily as far back as 1.6.2 if not earlier).

 

Thanks as always, diesieben07!

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.