Forum

> > CS2D > Scripts > ToTable
Forums overviewCS2D overview Scripts overviewLog in to reply

English ToTable

27 replies
Page
To the start Previous 1 2 Next To the start

old Re: ToTable

EngiN33R
Moderator Off Offline

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

user Obviously Exactly Myself has written
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.

old Re: ToTable

Obviously Exactly Myself
User Off Offline

Quote
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

old Re: ToTable

EngiN33R
Moderator Off Offline

Quote
user Obviously Exactly Myself has written
.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.

old Re: ToTable

Obviously Exactly Myself
User Off Offline

Quote
@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.

old Re: ToTable

Alistaire
User Off Offline

Quote
user Obviously Exactly Myself has written
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}

old Re: ToTable

Flacko
User Off Offline

Quote
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.

old Re: ToTable

Alistaire
User Off Offline

Quote
user Flacko has written
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"?

old Re: ToTable

Flacko
User Off Offline

Quote
Yes. If you want it to be even faster (by a negligible amount) Use a for i=1, #savefilestring loop.
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview