Jump to content

[1.7.10]Config not saving


The_Fireplace

Recommended Posts

So my config option FIRSTRUN is supposed to be set to false the first time running the game with the mod installed. However, when I open up the config gui, it still shows as true. If, while in the config gui, I set it to false, and I restart the game, it is true again. The output in the console shows up like it is supposed to. Here is my code:

 

@Mod(modid = "modcompat", name="Mod Compatibility Patch", version="1.0.0", acceptedMinecraftVersions = "1.7.10", guiFactory = "the_fireplace.modcompat.config.ModCompatGuiFactory")
public class ModCompatBase {
@Instance(value = "modcompat")
    public static ModCompatBase instance;
public static Configuration config;

@EventHandler
public void PreInit(FMLPreInitializationEvent event){
//Config code
config = new Configuration(event.getSuggestedConfigurationFile());
syncConfig();
//Config checking
	if(ModCompatConfigValues.FIRSTTIME == true){
		System.out.println("[ModCompat]Doing one-time scan...");
		ModCompatConfigValues.FIRSTTIME = false;
                        //I have tried putting syncConfig() here, same result as without it
	}
}

public static void syncConfig(){
ModCompatConfigValues.FIRSTTIME = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT).getBoolean();
if(config.hasChanged()){
        config.save();
}
}

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
     if(eventArgs.modID.equals("modcompat"))
        syncConfig();
}
}

 

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

When you change FIRSTTIME, you do not mark the config as changed.

Oh, and here is a bit of information you didn't know:

[code]ModCompatConfigValues.FIRSTTIME = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT).getBoolean()

This above does not change anything in the Configuration. This only gets the value of the property from the Configuration. It cannot be used to set it to another value.

 

Instead use:

[code]
public static Property FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT, "Set this to false to repeat first time setup");
if (!FIRSTTIME_PROPERTY.getBoolean()) {
   FIRSTTIME_PROPERTY.set(true);
   // do your other code for first time
}

That sets the property and marks the configuration as changed

Link to comment
Share on other sites

When you change FIRSTTIME, you do not mark the config as changed.

Oh, and here is a bit of information you didn't know:

[code]ModCompatConfigValues.FIRSTTIME = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT).getBoolean()

This above does not change anything in the Configuration. This only gets the value of the property from the Configuration. It cannot be used to set it to another value.

 

Instead use:

[code]
public static Property FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT, "Set this to false to repeat first time setup");
if (!FIRSTTIME_PROPERTY.getBoolean()) {
   FIRSTTIME_PROPERTY.set(true);
   // do your other code for first time
}

That sets the property and marks the configuration as changed

Ok, I've re-coded it as you said, now what do I do in syncConfig() to make this work?(It now seems to do the same thing as before) Here is the new code:

 

@Mod(modid = "modcompat", name="Mod Compatibility Patch", version="1.0.0", acceptedMinecraftVersions = "1.7.10", guiFactory = "the_fireplace.modcompat.config.ModCompatGuiFactory")
public class ModCompatBase {
@Instance(value = "modcompat")
        public static ModCompatBase instance;
public static Configuration config;
        public static Property FIRSTTIME_PROPERTY;
public static void syncConfig(){
        config.load();
ModCompatConfigValues.FIRSTTIME = FIRSTTIME_PROPERTY.getBoolean();
if(config.hasChanged()){
        config.save();
}
}
@EventHandler
public void PreInit(FMLPreInitializationEvent event){
//Config code
config = new Configuration(event.getSuggestedConfigurationFile());
FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT);
syncConfig();
//Config checking
	if(FIRSTTIME_PROPERTY.getBoolean() == true){
		System.out.println("[ModCompat]Doing one-time scan...");
		FIRSTTIME_PROPERTY.set(false);
		syncConfig();
	}
}

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
     if(eventArgs.modID.equals("modcompat"))
        syncConfig();
}
}

 

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

You are not loading your config.

Put a line with config.load() right after config = new Configuration( ....

Link to comment
Share on other sites

I suspect your syncConfig is reloading the configuration before it is first saved... thereby erasing your firsttime update.

Please repost your main class as it is now.  It is unnecessary to config.load() in syncConfig as the configuration should already be loaded and updated, it only needs to be read into variables and saved. In fact, you FIRSTTIME property check & set should be part of syncConfig anyways.

Link to comment
Share on other sites

Ok, so currently, it now switches firstrun to false, like it is supposed to, but it goes back to being true when I quit Minecraft and start it again. Here is the code:

 

@Mod(modid = "modcompat", name="Mod Compatibility Patch", version="1.0.0", acceptedMinecraftVersions = "1.7.2,1.7.10", guiFactory = "the_fireplace.modcompat.config.ModCompatGuiFactory")
public class ModCompatBase {
@Instance(value = "modcompat")
        public static ModCompatBase instance;
public static Configuration config;
        public static Property FIRSTTIME_PROPERTY;
public static void syncConfig(){
ModCompatConfigValues.FIRSTTIME = FIRSTTIME_PROPERTY.getBoolean();
if(config.hasChanged()){
        config.save();
}
}
@EventHandler
public void PreInit(FMLPreInitializationEvent event){
//Config code
config = new Configuration(event.getSuggestedConfigurationFile());
        config.load();
FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT);
syncConfig();
//Config checking
	if(FIRSTTIME_PROPERTY.getBoolean() == true){
		System.out.println("[ModCompat]Doing one-time scan...");
		FIRSTTIME_PROPERTY.set(false);
		syncConfig();
	}
}

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
     if(eventArgs.modID.equals("modcompat"))
        syncConfig();
}
}

 

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

You're missing what I'm telling you (important parts of it, anyways.)

 

Try this:

 

@Mod(modid = "modcompat", name="Mod Compatibility Patch", version="1.0.0", acceptedMinecraftVersions = "1.7.2,1.7.10", guiFactory = "the_fireplace.modcompat.config.ModCompatGuiFactory")
public class ModCompatBase {
@Instance(value = "modcompat")
        public static ModCompatBase instance;
public static Configuration config;
        public static Property FIRSTTIME_PROPERTY;

public static void syncConfig() {
FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT);
ModCompatConfigValues.FIRSTTIME = FIRSTTIME_PROPERTY.getBoolean();
// get other properties here
if(ModCompatConfigValues.FIRSTTIME) {
	System.out.println("[ModCompat]Doing one-time scan...");
	FIRSTTIME_PROPERTY.set(false);
}
if (config.hasChanged()) {
                config.save();
}
}
@EventHandler
public void PreInit(FMLPreInitializationEvent event){
//Config code
config = new Configuration(event.getSuggestedConfigurationFile());
        config.load();
syncConfig();
}

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
     if(eventArgs.modID.equals("modcompat"))
        syncConfig();
}
}

 

 

mkay?

Link to comment
Share on other sites

You're missing what I'm telling you (important parts of it, anyways.)

 

Try this:

 

@Mod(modid = "modcompat", name="Mod Compatibility Patch", version="1.0.0", acceptedMinecraftVersions = "1.7.2,1.7.10", guiFactory = "the_fireplace.modcompat.config.ModCompatGuiFactory")
public class ModCompatBase {
@Instance(value = "modcompat")
        public static ModCompatBase instance;
public static Configuration config;
        public static Property FIRSTTIME_PROPERTY;

public static void syncConfig() {
FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT);
ModCompatConfigValues.FIRSTTIME = FIRSTTIME_PROPERTY.getBoolean();
// get other properties here
if(ModCompatConfigValues.FIRSTTIME) {
	System.out.println("[ModCompat]Doing one-time scan...");
	FIRSTTIME_PROPERTY.set(false);
}
if (config.hasChanged()) {
                config.save();
}
}
@EventHandler
public void PreInit(FMLPreInitializationEvent event){
//Config code
config = new Configuration(event.getSuggestedConfigurationFile());
        config.load();
syncConfig();
}

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
     if(eventArgs.modID.equals("modcompat"))
        syncConfig();
        
}
}

 

 

mkay?

Ok, tried that, and it now sets to false as it is supposed to, and upon reloading the game, it remains false. I have run in to another problem, however. When I set it to true again in the Config GUI, it doesn't run the code again. I set up a System.out.println("[ModCompat] Code Activated"); in the onConfigChanged code, as shown below, and it doesn't activate after setting the config in the Config GUI.

 

@Mod(modid = "modcompat", name="Mod Compatibility Patch", version="1.0.0", acceptedMinecraftVersions = "1.7.2,1.7.10", guiFactory = "the_fireplace.modcompat.config.ModCompatGuiFactory")
public class ModCompatBase {
@Instance(value = "modcompat")
        public static ModCompatBase instance;
public static Configuration config;
        public static Property FIRSTTIME_PROPERTY;

public static void syncConfig() {
FIRSTTIME_PROPERTY = config.get(Configuration.CATEGORY_GENERAL, ModCompatConfigValues.FIRSTTIME_NAME, ModCompatConfigValues.FIRSTTIME_DEFAULT);
ModCompatConfigValues.FIRSTTIME = FIRSTTIME_PROPERTY.getBoolean();
// get other properties here
if(ModCompatConfigValues.FIRSTTIME) {
	System.out.println("[ModCompat]Doing one-time scan...");
	FIRSTTIME_PROPERTY.set(false);
}
if (config.hasChanged()) {
                config.save();
}
}
@EventHandler
public void PreInit(FMLPreInitializationEvent event){
//Config code
config = new Configuration(event.getSuggestedConfigurationFile());
        config.load();
syncConfig();
}

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
System.out.println("[ModCompat] Code Activated");
     if(eventArgs.modID.equals("modcompat")){
        syncConfig();
        }
}
}

 

EDIT: Initial problem is fixed, creating a new thread for the new problem

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

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.