Forum

> > CS2D > Scripts > read/write
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch read/write

16 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt read/write

EnderCrypt
User Off Offline

Zitieren
hi
i would want to write/read string to a file

could someone give me a simple example, that just saves a string
and another example that read, and also to just line

thx

alt Re: read/write

KaBooMa
User Off Offline

Zitieren
Here is a easy script that will save and load your hp!

Spoiler >


Hope you find it somewhat useful. Remember, The save is in your lua folder.

alt Re: read/write

EnderCrypt
User Off Offline

Zitieren
ah... now i andurstand, ok also how to read/write on lets say..

next line?

thx

alt Re: read/write

Yasday
User Off Offline

Zitieren
\n is the newline character.
1× editiert, zuletzt 27.02.11 15:37:41

alt Re: read/write

EnderCrypt
User Off Offline

Zitieren
yeah i searched like 10 times today but i didnt se this, thx
edit:

also if i wanna overwrite a line with a variable, what do i do cause when i try file:write("\n") then it just overwrite everything, is there anything that allows me to skip line without overwriting it?
2× editiert, zuletzt 28.02.11 12:36:52

alt Re: read/write

KimKat
GAME BANNED Off Offline

Zitieren
Not if you use "a+" it will just open existing file and add more to it.
"w+" deletes everything in a file before attempting to write to it. These are more useful, I hope.
1
2
3
4
5
6
path = saves -- The directory where you will place the save.
file_save = {0 = [path/text document.txt]}

function save()
	file:write(file_save[0],"w+")
end

Here's a tutorial for y'all.
SaveTableToFile

alt Re: read/write

EnderCrypt
User Off Offline

Zitieren
no i want to write on a certain line, i got the line number in a variable, now i wanna write to it

alt Re: read/write

Flacko
User Off Offline

Zitieren
Yasday hat geschrieben
io.write(player(id,"health").."\n\n\n\n\n")

You don't need to concatenate when writing to a file.
Instead you should pass it as different parameters to save yourself from doing needless concatenations.

Zitat
also if i wanna overwrite a line with a variable

Ohh, it's very simple, you just have to rewrite the whole file instead of the part you want to edit
It's not possible to write to a part of a file (that's why we got databases, but not in lua)

alt Re: read/write

EnderCrypt
User Off Offline

Zitieren
hm ok, then can i ask, how long does it take for lua to read like 1000 lines and place in a array with the help of a loop?

and how long to write 1000 lines from array using w mode in a loop?

alt Re: read/write

Lee
Moderator Off Offline

Zitieren
less than 1 millisecond

At this point, seeing as how you are using a very inefficient serialization method to begin with, I really doubt that the rumtime complexity of IO is something that you have to worry about.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht