Forum

> > CS2D > Scripts > Save Error (true/false)
Forums overviewCS2D overview Scripts overviewLog in to reply

English Save Error (true/false)

7 replies
To the start Previous 1 Next To the start

old Save Error (true/false)

Ridho
User Off Offline

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

old Re: Save Error (true/false)

Talented Doge
User Off Offline

Quote
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

old Re: Save Error (true/false)

Ridho
User Off Offline

Quote
user Talented Doge has written
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?

old Re: Save Error (true/false)

Dousea
User Off Offline

Quote
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

old Re: Save Error (true/false)

MikuAuahDark
User Off Offline

Quote
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
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview