Saving values to a prc file [SOLVED]

Should setting setValue on a Config* object set the value only in the game instance? Or should it set it in the prc file?

I am using the following code (taken out of several functions of my code).

self.scrollSpeed = ConfigVariableString(SCROLL_SPEED, "0.3")
self.currentScrollSpeed = float(self.scrollSpeed.getValue())

scrollSpeed = self.scrollSpeedSlider.value/100.00
self.scrollSpeed.setValue("%s" % scrollSpeed)
print self.scrollSpeed.getValue()

Printing out self.scrollSpeed.getValue() shows the correct value, however that value is not written back to the PRC file. Is there a way in Panda to write the value back to the prc file (or do I need code something to do it).

I had originally written a registry class to write all values to the registry in windows. This class works great, however I didn’t want to handle multiple ways of retrieving/saving config data (for multiple os’) and so I am going back and redoing that portion of my code to use a prc file for storing game data.

i save my data into my config like:

cfgFile = open('config/Config.prc', 'w')
cfgFile.write("my-config-var " +mcv-value +"\n")


remember u have to save/write ALL stuff that should be in ur file, because ur not adding content into the config, but overwriting it!


sunday_coder, you said,
“remember u have to save/write ALL stuff that should be in ur file, because ur not adding content into the config, but overwriting it!”

is it possible to just append to it.
I ask mainly because this file is a mystery to me. I am very new to Panda and just now getting into antialiasing on my screen. Its not working, I think because I have yet to add “framebuffer-multisample 1”
“multisamples 2” to the Config.prc file as per the manual. If this is the case how do I add it without srewing up the whole file by overwriting everything (which I haven’t a clue what it is).

Nevermind, I just figured it all out. Can;t believe how narrow my vision was

I’m very curious as well to know if there’s a built-in Panda way to write configuration data back to a file.

Yes. The return value of loadConfigPage() or loadConfigData() is a ConfigPage object (or you can pull an existing ConfigPage object from the cpMgr). This object has a write() method that dumps its output to a stream; from Python, you can give it a StringStream to write to a string, or an OFileStream to write the data to disk.

But, writing out a formatted list of lines using Python’s standard write() method works perfectly well, too. :slight_smile:


Great - thanks!

hah, thats what I was originally looking for. Oh well, I ended up just writing a class to write the file each time settings are saved.