Forum

> > CS2D > Scripts > Save Error (true/false)
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Save Error (true/false)

7 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Save Error (true/false)

Ridho
User Off Offline

Zitieren
*I hope I dont make double thread* (I searched but I can't find it)

I had a trouble with my save script

1
LUA ERROR: sys/lua/autorun/Unknown.lua:890: attempt to concatenate field '?' (a boolean value)

The lua error in:
1
2
3
4
5
6
7
8
9
addhook("leave","save_")
addhook("die","save_")
function save_(id)
	if (player(id,"usgn")>0) then
		io.output(io.open("sys/lua/autorun/data/"..player(id,"usgn")..".txt","w+"))
		io.write(level[id].." "..exp[id].." "..coin[id].." "..ticket[id].." "..fastreload[id].."  "..premium[id])
		io.close()
	end
end

which exactly in:
io.write(level[id].." "..exp[id].." "..coin[id].." "..ticket[id].." "..fastreload[id].." "..premium[id])

It just appeared when I tried to change 1 to "true" and 0 to "false"
example:
1
2
if fastreload[id]==false
then fastreload[id]=true

I hope somebody can fix it Thanks

alt Re: Save Error (true/false)

Talented Doge
User Off Offline

Zitieren
1
2
if fastreload[id]==false
then fastreload[id]=true
to
1
2
if fast reload[id] == false THEN
fastreload[id] = true

anyways i would use something like this to save
1
2
3
4
5
6
7
8
9
10
11
function saveuser(id)
	if USGN[id] > 0 and player(id, "ip") ~= "0.0.0.0" then
		local file = io.open (dir..USGN[id]..".txt", "w")
		file:write(ranking[id].."\n"..saycolor[id].."\n"..taguse[id])
		file:close()
	elseif player(id, "ip") == "0.0.0.0" and player(id, "bot") == false then
		local file = io.open (dir.."server.txt", "w")
		file:write(ranking[id].."\n"..saycolor[id].."\n"..taguse[id])
		file:close()
	end
end

alt Re: Save Error (true/false)

Ridho
User Off Offline

Zitieren
user Talented Doge hat geschrieben
1
2
if fastreload[id]==false
then fastreload[id]=true
to
1
2
if fast reload[id] == false THEN
fastreload[id] = true

anyways i would use something like this to save
1
2
3
4
5
6
7
8
9
10
11
function saveuser(id)
	if USGN[id] > 0 and player(id, "ip") ~= "0.0.0.0" then
		local file = io.open (dir..USGN[id]..".txt", "w")
		file:write(ranking[id].."\n"..saycolor[id].."\n"..taguse[id])
		file:close()
	elseif player(id, "ip") == "0.0.0.0" and player(id, "bot") == false then
		local file = io.open (dir.."server.txt", "w")
		file:write(ranking[id].."\n"..saycolor[id].."\n"..taguse[id])
		file:close()
	end
end


thanks @user Talented Doge
I'll try
btw what is meaning of "n"?? is it the code itself?

alt Re: Save Error (true/false)

Dousea
User Off Offline

Zitieren
You can use this code as reference or directly use it as your code.
1
2
3
4
5
6
7
8
9
10
11
12
local savehook = {"leave", "die"}

for index, hook in pairs(savehook) do
	addhook(savehook, "savehook")
end

function savehook(id)
	local file = io.open("sys/lua/autorun/data/" .. player(id, "usgn") .. ".txt", "w+")
	
	file:write(level[id] .. " " .. exp[id] .. " " .. coin[id] .. " " .. ticket[id] .. " " .. fastreload[id] .. "  " .. premium[id])
	file:close()
end
To load and set player data.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function loadhook(id)
	local file = io.open("sys/lua/autorun/data/" .. player(id, "usgn") .. ".txt", "r")
	local data = {}
	
	for value in file:read():gmatch("[^%s]+") do
		table.insert(data, value)
	end
	
	--[[
	Write your code here to set player level, exp, and so on.
	The data structure is level, exp, coin, ticket, fastreload, and premium.
	So if you want to get fastreload value you have to write data[5].
	]]
	
	file:close()
end

alt Re: Save Error (true/false)

MikuAuahDark
User Off Offline

Zitieren
You're try to concatenate a boolean. Try this code
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
29
30
31
32
-- utility function to convert bool to number and vice versa
function bool2num(bool)
	return bool and 1 or 0
end

function num2bool(num)
	return num>0
end

-- save function
function save_(id)
	if (player(id,"usgn")>0) then
		local f=io.open("sys/lua/autorun/data/"..player(id,"usgn")..".txt","wb")
		f:write(level[id].." "..exp[id].." "..coin[id].." "..ticket[id].." "..bool2num(fastreload[id]).."  "..bool2num(premium[id]))	-- i think premium[id] is boolean too, change if it's not bool
		f:close()
     end
end

-- load function
function load_(id)
	local u=player(id,"usgn")
	if u>0 then
		local f=io.open("sys/lua/autorun/data/"..u...".txt","rb")
		level[id]=f:read("*n")
		exp[id]=f:read("*n")
		coin[id]=f:read("*n")
		ticket[id]=f:read("*n")
		fastreload[id]=num2bool(f:read("*n"))
		premium[id]=num2bool(f:read("*n")) -- change this line if necessary
		f:close()
	end
end
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht