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")
SavePos.write(str(self.blaze.getPos()))

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")
SavePos.write(str(self.blaze.getPos()))

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.

David

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")
self.SavePos.write(str(self.blaze.getX())+str(",")+str(self.blaze.getY())+str(",")+str(self.blaze.getZ()))
self.SavePos.close()

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()
self.LoadPos.close()

And to set my position:

self.blaze.setPos(self.SavePos)

I get this error:

DirectStart: Starting the game. 
Known pipe types:
  wglGraphicsPipe
(all display modules loaded.)
['-3.30305886269,-3.27693843842,-0.0341884605587']
Traceback (most recent call last):
  File "maincourse.py", line 530, in <module>
    w = World()
  File "maincourse.py", line 97, in __init__
    self.blaze.setPos(self.SavedPos)
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
    self.blaze.setPos(pos)

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.

Thanks:)

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.