Forum

> > CS2D > Scripts > ToTable
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch ToTable

27 Antworten
Seite
Zum Anfang Vorherige 1 2 Nächste Zum Anfang

alt Re: ToTable

EngiN33R
Moderator Off Offline

Zitieren
Okay, I've read the thread and I've got a couple of questions.

user Obviously Exactly Myself hat geschrieben
It seems that there was only one line with the word "ToTable".


Was there only one occurence of "ToTable"? Did you search for that or "toTable"? The case matters.

What is the format of your save file? Maybe we could extrapolate a toTable function from that.

alt Re: ToTable

Obviously Exactly Myself
User Off Offline

Zitieren
Yes,
"Find" is not case-sensitive,
.SAV,
Hope it answer those questions.

EDIT: Do I need to add this part? I found this part in almost all scripts with saves.
1
2
3
4
5
6
7
8
9
10
11
12
function ToTable(t,match)
	local cmd = {}
	if not match then
		match = "[^%s]+"
	else
		match = "[^"..match.."]+"
	end
	for word in string.gmatch(t,match) do
		table.insert(cmd,word)
	end
	return cmd
end

alt Re: ToTable

EngiN33R
Moderator Off Offline

Zitieren
user Obviously Exactly Myself hat geschrieben
.SAV,


I didn't mean the extension... I mean how the actual content of the save file looks like.

Try putting that code in, I guess. But it's basically what user UnkN gave you.

alt Re: ToTable

Obviously Exactly Myself
User Off Offline

Zitieren
@user EngiN33R:
1
(uphealth[id].." "..upspeed[id].." "..uprate[id].." "..points[id].." "..rects[id].." "..rounds[id].." "..tris[id].." "..octs[id].." "..duals[id].." "..special[id].." "..shape[id])

-----

BTW, It's already working, thanks for the help, though.

alt Re: ToTable

Alistaire
User Off Offline

Zitieren
user Obviously Exactly Myself hat geschrieben
1
(uphealth[id].." "..upspeed[id].." "..uprate[id].." "..points[id].." "..rects[id].." "..rounds[id].." "..tris[id].." "..octs[id].." "..duals[id].." "..special[id].." "..shape[id])


Holy christ that's a descriptive save file.

----

No seriously, a savefile should look like e.g this;

1
plr.stats[21737] = {1, 2, 4, 1, 8, 2}

alt Re: ToTable

Flacko
User Off Offline

Zitieren
A save file should look like
1
1 2 4 1 8 2
dofile'ing a save file is slow and not safe.

Also, this is how you're supposed to write to the file:
1
file:write(data1," ",data2, " ", ..., "\n")
I've seen a lot of people concatenating a ton of shit before writing to the file which is unnecessary and makes your script slower.

The layout in memory should be just like @user Alistaire: said.
health[id], armor[id], etc. just makes your code uglier.

alt Re: ToTable

Alistaire
User Off Offline

Zitieren
user Flacko hat geschrieben
A save file should look like
1
1 2 4 1 8 2
dofile'ing a save file is slow and not safe.


So my example would have to load like this partially pseudocode;

1
2
3
4
5
6
savefilestring = file.read everything
local l = totable(savefilestring)
plr.stats[usgn] = {}
for k, v in pairs(l) do
	plr.stats[usgn][k] = v
end

To make it "fast and safe"?

alt Re: ToTable

Flacko
User Off Offline

Zitieren
Yes. If you want it to be even faster (by a negligible amount) Use a for i=1, #savefilestring loop.
Zum Anfang Vorherige 1 2 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht