Jump to content

Recommended Posts

Posted

Like what others have said, if you have a reference to your Config object stored somewhere, such as your Main class, then writing to it from a command is as simple as using that reference to access a value in the file like you do when you first load the config.

 

However, what would be the point of this? Do you just want the command to change the config setting that is currently being used in the game? If so, you need to change THAT reference, not write to the config file - the only reason you would write to the config file is to save the change for the next time the player loads the game, but you'd still have to change the current value of the config setting for it to have any immediate effect.

Posted

However, what would be the point of this? Do you just want the command to change the config setting that is currently being used in the game? If so, you need to change THAT reference, not write to the config file - the only reason you would write to the config file is to save the change for the next time the player loads the game, but you'd still have to change the current value of the config setting for it to have any immediate effect.

 

To clarify a bit more. While it is possible to read from the actual config file every time you need one of the config settings, that causes a file read access which can affect performance. So best practice is to read the config file once during the mod initialization and store the values in public fields that can then be accessed in your code.

 

So assuming you have it set up that way, in the command processing code what you want to invoke is a config "sync" method which both writes to the config file but also updates any fields that are supposed to hold values read from the config file.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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