Forum

> > CS2D > Scripts > Load function is not working.
Forums overviewCS2D overview Scripts overviewLog in to reply

English Load function is not working.

4 replies
To the start Previous 1 Next To the start

old Load function is not working.

muxarus
User Off Offline

Quote
I have save function and load func. So save func is working good but the load is not loading variables from a .txt file.
There is a code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
elo = {}
elo_test_try = {}
pl = {}

for id=1,32 do
pl[id]={}
elo_test_try[id]=5
elo[id]=40
end

addhook("join","_join")
function _join(id)
if player(id,"usgn")>0 then
local dir="sys/lua/accounts/%s.txt"
local file = io.open(dir:format(player(id,"usgn"), "r"))
if file then
local string1, string2, string3, string4, string5 = file:read("*n","*n","*n","*n","*n")
elo[id] = string2
elo_test_try[id] = string3
pl[id].tag = string4
file:close()
end
end

problems:
1) this code is NOT loading string1. so any variable that =string1 will be nil or *n (only elo[id] will be *n but other vars will be nil).
2) this code is loading only 1 variable that first than others.

old Re: Load function is not working.

Talented Doge
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function loaduser(id)
	if USGN[id] > 0 then
		local file = io.open (dir..USGN[id]..".txt", "r")
		if file then
			local ranking_f,saycolor_f, taguse_f = file:read ("*l","*l","*n")
			ranking[id] = tonumber(ranking_f) or 0
			saycolor[id] = saycolor_f or "234205005"
			taguse[id] = tonumber(taguse_f) or 0
			saytag[id] = saytags[ranking[id]]
			file:close()
		else
			ranking[id] = 0
			saycolor[id] = "234205005"
			taguse[id] = 0
			saytag[id] = saytags[ranking[id]]
		end
	elseif player(id, "bot") then
		ranking[id] = 0
		saycolor[id] = "234205005"
		taguse[id] = 0
		saytag[id] = "(Bot)"
	else
		ranking[id] = 0
		saycolor[id] = "234205005"
		taguse[id] = 0
		saytag[id] = saytags[ranking[id]]
	end
end

I actually use the approach of saving each variable per line.

old Re: Load function is not working.

Yates
Reviewer Off Offline

Quote
You should instead of writing things into a .txt file dump it into a Lua file and dofile it when you want to load data. You can then simply use the variables and overwrite the file to save.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview