Troubles saving a txt file

Hi guys, sorry for so many posts lately. I’ve been on a role trying t get things done.
But I’m having troubles saving a text file.

SavePos = open("SavePos.txt", "w")

Then I get the error:

IOError: [Errno 2] No such file or directory

But when I do:

SavePos = open("C:/Users/Britany/Desktop/Panda3D/Panda3D-1.7.2/models/Blaze3D/Data/SavePos.txt", "w")

Then I get the error:

IOError: [Errno] No such file or directory: 'C:/Users/Britany/Desktop/Panda3D/Panda3D-1.7.2/models/Blaze3D/Data/SavePos.txt'

I already have a blank text file names SavePos.txt, but it says the path is wrong.
Why is this?

-Again, sorry for asking so much this week.

It probably means you don’t have write permission to the file. Try deleting the file first.


Nope, I did delete the file, run the game, and I still get the errors. I put the file back, and I still get errors.

Got it. Turns out my directory WAS off. I did a little experimenting, and I guess they automatically save and open from desktop. I didn’t know this, so my saved file was trying to go like this:
C:/Users/Britany/Desktop/C:/Users/Britany/Desktop/ on so on…

Actually, I found another problem I’m having lol.

I saved my characters position by doing this:

self.SavePos = open("PosData.txt", "w")

And it would update every time I stop moving.
To load the data, then set my position on start-up, I used this:

self.LoadPos = open("PosData.txt", "r")
self.SavedPos = self.LoadPos.readLines()

And to set my position:


I get this error:

DirectStart: Starting the game. 
Known pipe types:
(all display modules loaded.)
Traceback (most recent call last):
  File "", line 530, in <module>
    w = World()
  File "", line 97, in __init__
TypeError: NodePath.setPos() argument 1 must be VBase3, not list

**** End of process output ****

readLines gives you a list of strings, one for each line in the file. That list will need further processing to get it back into the form of floats or VBase3 instances. The error message is telling you this when it says “argument 1 must be VBase3, not list”. A simple parsing loop might look something like this:

for line in self.SavedPos:
    # strip spaces out of the string
    line = line.replace(" ", "")
    # split into three strings split at the commas
    xstr, ystr, zstr = line.split(",")
    # convert the strings to float values and create a Pos3 object
    pos = Pos3(float(xstr), float(ystr), float(zstr))

    # set the position

Okay, so you only had one nodepath in your code so with multiple positions you’ll have to work out how to decide what nodepaths to apply them to in what order.

Sorry, I figured it out. Oddly, your way didn’t quite work the way I wanted it to. But I figured it out, so it’s all good.


At least you got it working. I made a mistake in my example. I wrote Pos3, that was supposed to be Point3, but anyway setPos can also take 3 individual floats.

No problem.
I found I could just write pieces of a text in a task, then continue it forever, that way my text files update every frame. I did that, and separated everything by using \n for a new row.
Then I just read the text file, and used certain lines from their. Works great.