Forum

> > CS2D > Scripts > LUA question - Saving
Forums overviewCS2D overview Scripts overviewLog in to reply

English LUA question - Saving

5 replies
To the start Previous 1 Next To the start

old LUA question - Saving

Infinite Rain
Reviewer Off Offline

Quote
Guys i need help to save arrays

for example:
when player leave the server arrays
x[id]
y[id]
save in another file on server's cs2d dir (USGNS)

when he join the server file will be loaded

can someone help mke with this pleeasE?

old Re: LUA question - Saving

Yasday
User Off Offline

Quote
Here some functions:
1
2
3
4
5
6
7
8
9
10
11
12
13
function save(what, where, how)
if how == nil or how == "r" then how = "w" end
local f = io.open(where, how)
f:write(what)
f:close()
end

function load(what, where)
local f = io.open(where, "r")
local r = f:read("*"..what)
f:close()
return r
end
Use them like this:
1
2
save(x[id], "sys/lua/saves/"..player(id, "usgn")..".txt")
x[id] = load("n", "sys/lua/saves/"..player(id, "usgn")..".txt")

But I would prefer to save everything in one file.

old Re: LUA question - Saving

Vectarrio
User Off Offline

Quote
I think you want to save whole array in one file
then you just must save it with "for" loop.
and of course, you must then know, where is array, and where are other vars.
But I don't have a code right now, sry.

old Re: LUA question - Saving

TimeQuesT
User Off Offline

Quote
just split them with a ";". like ";5;;3;;22;"
then when you let the file read just the the values between them and put them in a table..

edit:

i copied it from my dm script so don't wonder about "dm"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
local text = ""
for l in io.lines("sys/lua/einstellung") do
text = string.format("%s %s",text,l)
end

local current = 0
local charpos = 0
for char = 1,string.len(text) do
if string.sub(text,char,char)==";" then

if charpos~=0 then
current = current + 1
dm.options[current] = tonumber(string.sub(text,charpos+1,char-1))
charpos = 0
elseif charpos==0 then
charpos = char
end
end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview