custom prc options?

Hello, I’ve heard you can have custom prc config variables, but how do you tell Panda what to do with those variables?
like

dosomething #t

I’m guessing there is a way to set a function which will be ran when the value is equal to something (like 1 or #t.

from panda3d.core import ConfigVariableBool

var = ConfigVariableBool("dosomething")
if var:
  print "Is set"

Check the API reference of ConfigVariable* for more information on setting things such as default values, using enumerated variables, etc.

OK, what about setting the value and saving it back to the config file?

You can’t do that. The prc file is meant to be edited by a human with a text editor, not by a computer program.

David

That doesnt make sense.
You have the fullscreen, resolution, graphics api, antialiasing settings which just about any game allows to edit, and usually the edits are applied on next startup.

Having two configuration files seems like a bad design.

The prc file is not meant to be a place to store your user configuration options. Panda doesn’t provide that feature for you; you’re expected to do it yourself if you want it (it’s easy to do in Python).

The prc file is instead meant to be a place to store the configuration options that are specific to your game and don’t change based on the user’s preference.

David

I have to agree with redpanda on this. Keeping multiple configuration files doesn’t make much sense, especially since the prc file is convenient for storing stuff like resolution, which should definitely be subject to user configuration with some, preferably, in-game menu.

While granted it would be a nice feature for Panda to provide a user-editable config file, this is not the purpose of the prc file.

If Panda ever does provide this feature, or if you build it yourself, it will be with a different file format (and you can choose the file format that is most appropriate for your needs if you build it yourself). In this case, you will not store resolution and such in the prc file. You will only use the prc file to store hardcoded config settings.

You can put resolution and such in the prc file, as a convenience during development or if you don’t want to mess around with all the nonsense that a user-configurable settings file entails. But when you build your final product, if your design includes user configurable screen resolution (and I hope it does, since that’s a useful feature), then you won’t want to put the screen resolution in the prc file, because as you say, that would be redundant with whatever config file you do put it in.

That doesn’t mean the prc file is useless or that it needs to have writable settings. It just means it’s not useful as a user-configurable config file. You can use a different file for that, and that’s a perfectly reasonable thing to do.

If anyone wanted to contribute code to Panda to add a user-configurable setting file, that would be fine. We haven’t done it yet because (a) it’s so easy to do in Python anyway, and (b) it’s often very application-specific.

In fact, it’s probably possible to use the prc system to implement rewritable files (and I think some people have done this). But this isn’t what it was designed for, and it isn’t what it is good at.

David