|
Answer» hey all,
I'm looking for a way to read and write to certain lines of a txt file. The files looks like this;
[Frozen *censored* - Save Data]
[Player info] -name Blastman -Current level 1 -health 80 -ammo 25 -weapon Pistol -Last Save data 19.6.2008
[Avaiable Weapons] Pistol Dual Pistols Sub Machine Gun Machine Gun
[Invertory] Rusty Key
I'm aware a FOR loop could pull certain lines into a variable for me to use, but I don't know how??
Also how could I update one line within this file???
Basically I'm writing a game and I have been using different txt files for all the different THINGS I want to STORE. However as the game has progressed the number of files is BECOMING a little unmanageable.
any help would be fantastic!!
Cheers in ADVANCE guys!!Reading from a file has been answered many times, a quick search will identify some approaches.
As for updating a line, you will have to read / write each line in turn, when the line you want to CHANGE turns up, you need to make your change and then write the updated value out.
Grahamumm, thats too long winded me thinks.
I think that vbs might be able offer a find and replace. I'll give that line a go.
Cheers anyway.why does everyone find interest in writing little games in DOS? That's not fun at all. If you want to write games, see here. Learn the language. Also , if you want to parse files like this, you can use configparser. Makes things easier.
|