Forum

> > CS2D > Scripts > Lua Error
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua Error

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

old Lua Error

Jhony
User Off Offline

Quote
When player Join
if USGN puted in archive "USGNS"
He can open the menu ( Action 1 (F2))
But No Works
Look Error down !
Help Me

Spoiler >


More >


Line 48 : for _, usgn in ipairs(sys/lua/usgns/"..player(id,"usgn")..".txt"") do

old Re: Lua Error

oxytamine
User Off Offline

Quote
1
for _, usgn in ipairs(sys/lua/usgns/"..player(id,"usgn")..".txt"") do
You haven't closed quotes properly. Append this fix.
1
for _, usgn in ipairs("sys/lua/usgns/"..player(id,"usgn")..".txt") do

old Re: Lua Error

Jhony
User Off Offline

Quote
user oxytamine has written
1
for _, usgn in ipairs(sys/lua/usgns/"..player(id,"usgn")..".txt"") do
You haven't closed quotes properly. Append this fix.
1
for _, usgn in ipairs("sys/lua/usgns/"..player(id,"usgn")..".txt") do

New ERROR D=

LUA ERROR: sys/lua/userxd.lua:48: bad argument #1 to 'ipairs' (table expected, got string)

old Re: Lua Error

oxytamine
User Off Offline

Quote
Make sure you've totally restarted your CS2D server. Try using dedicated version. That error is very odd and it keeps confusing Lua coders for a long time.

old Re: Lua Error

Jhony
User Off Offline

Quote
user oxytamine has written
Make sure you've totally restarted your CS2D server. Try using dedicated version. That error is very odd and it keeps confusing Lua coders for a long time.


When Start the server
No Have error in console
when press the button F2 ( Action 1 )
Appears the error in console :

LUA ERROR: sys/lua/userxd.lua:48: bad argument #1 to 'ipairs' (table expected, got string)

old Re: Lua Error

Apache uwu
User Off Offline

Quote
1
2
3
4
5
for _, usgn in ipairs(sys/lua/usgns/"..player(id,"usgn")..".txt"") do
	if act == 1 then -- F2
		menu(id,"Menu,lol")
	end
end

Doesn't make sense, are you trying to show the menu to everyone or just a single player?

If it's a single player simply remove the for statement like so:

1
2
3
if act == 1 then -- F2
		menu(id,"Menu,lol")
	end

If it's to everyone replace ID with 0:

1
2
3
if act == 1 then -- F2
		menu(0,"Menu,lol")
	end

old Re: Lua Error

Jhony
User Off Offline

Quote
user Apache uwu has written
1
2
3
4
5
for _, usgn in ipairs(sys/lua/usgns/"..player(id,"usgn")..".txt"") do
	if act == 1 then -- F2
		menu(id,"Menu,lol")
	end
end

Doesn't make sense, are you trying to show the menu to everyone or just a single player?

If it's a single player simply remove the for statement like so:

1
2
3
if act == 1 then -- F2
		menu(id,"Menu,lol")
	end

If it's to everyone replace ID with 0:

1
2
3
if act == 1 then -- F2
		menu(0,"Menu,lol")
	end


That's not what I want
read the topic again

old Re: Lua Error

Apache uwu
User Off Offline

Quote
If you can not explain you problem, none of us can help you. If you're going to be rude, I'm not going to help you.

old Re: Lua Error

Jhony
User Off Offline

Quote
user Apache uwu has written
If you can not explain you problem, none of us can help you. If you're going to be rude, I'm not going to help you.


When player join in server
if the usgn of player is puted in USGNS folder (sys/lua/usgns)
he can open the menu
if usgn NOT puted
he can not open the menu

old Re: Lua Error

Apache uwu
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
--Replace these parts
addhook("serveraction","_serveraction")

addhook("serveraction","update")
function update(id,act)
     if fileExists("sys/lua/usgns/"..player(id,"usgn")..".txt") then
		if act == 1 then -- F2
			menu(id,"Menu,lol")
		end
	end
end

--Add this part
function fileExists(location)
	local f=io.open(location)
	if f~=nil then
		io.close(f)
	end
	return f~=nil
end

old Re: Lua Error

Jhony
User Off Offline

Quote
user Apache uwu has written
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
--Replace these parts
addhook("serveraction","_serveraction")

addhook("serveraction","update")
function update(id,act)
     if fileExists("sys/lua/usgns/"..player(id,"usgn")..".txt") then
		if act == 1 then -- F2
			menu(id,"Menu,lol")
		end
	end
end

--Add this part
function fileExists(location)
	local f=io.open(location)
	if f~=nil then
		io.close(f)
	end
	return f~=nil
end


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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function readfile(filelocation, linenum) 
savestr = {}
saveline=1
for line in io.lines(filelocation) do 
savestr[saveline]=line
saveline=saveline+1
end
return savestr[linenum]
end

function totable(t,match)
local cmd = {}
if not match then match = "[^%s]+" end
for word in string.gmatch(t, match) do
table.insert(cmd, word)
end
return cmd
end

addhook("say","a")
function a(id,txt)
local p = totable(txt)
local cmd = (p[1])
     if cmd == "@give" then
          local us = tonumber(p[2])
          if us > 0 then
          File = io.open("sys/lua/usgns/"..us..".txt", "a")
          return 1
          end
     return 1
     end
end

addhook("join","save_join") -- When join load
function save_join(id)
if player(id,"usgn") > 0 then
local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
          local file = io.open(filename)
          if file then
               VALUE[id] = readfile(file, 1) --read a value in the line 1
               VALUE[id] = readfile(file, 2) --same but in the line 2
          end
end
end

addhook("serveraction","update")
function update(id,act)
if fileExists("sys/lua/usgns/"..player(id,"usgn")..".txt") then
if act == 1 then -- F2
menu(0,"Menu,lol")
end
end
end

addhook("menu","menus")
function menus(id,t,b)
if t == "Menu" then
if b == 1 then
msg2(id,"Works!")
end
end
end


function fileExists(location)
     local f=io.open(location)
     if f~=nil then
          io.close(f)
     end
     return f~=nil
end

Yeah, Works but have error in console , if usgn puted
when press F2 , the menu appears , but when press F2
appears error in console :
LUA ERROR: sys/lua/userxd.lua:4: bad argument #1 to 'lines' (string expected, got userdata)

This error does something?

old Re: Lua Error

Apache uwu
User Off Offline

Quote
Well since /usgns/89367.txt is empty,

1
2
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2

Can't read properly, it seems you are trying to create a save system, however you give does nothing but create the file.

old Re: Lua Error

Jhony
User Off Offline

Quote
user Apache uwu has written
Well since /usgns/89367.txt is empty,

1
2
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2

Can't read properly, it seems you are trying to create a save system, however you give does nothing but create the file.


No offense
not want to create anything within USGNS/89367
but if it is empty, with nothing
this hurts, I keep it empty?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I Deleted the line :

1
2
3
4
if file then
               VALUE[id] = readfile(file, 1) --read a value in the line 1
               VALUE[id] = readfile(file, 2) --same but in the line 2
          end

and works
solved

old Re: Lua Error

Apache uwu
User Off Offline

Quote
Since you don't want to load anything simply remove

1
2
3
4
5
6
7
8
9
10
11
addhook("join","save_join") -- When join load
function save_join(id)
	if player(id,"usgn") > 0 then
		local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
		local file = io.open(filename)
		if file then
			VALUE[id] = readfile(file, 1) --read a value in the line 1
			VALUE[id] = readfile(file, 2) --same but in the line 2
		end
	end
end

old Re: Lua Error

sheeL
User Off Offline

Quote
user Apache uwu has written
Since you don't want to load anything simply remove

1
2
3
4
5
6
7
8
9
10
11
addhook("join","save_join") -- When join load
function save_join(id)
	if player(id,"usgn") > 0 then
		local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
		local file = io.open(filename)
		if file then
			VALUE[id] = readfile(file, 1) --read a value in the line 1
			VALUE[id] = readfile(file, 2) --same but in the line 2
		end
	end
end


no no no no no @user Apache uwu: , remove the line :

1
2
3
4
if file then
			VALUE[id] = readfile(file, 1) --read a value in the line 1
			VALUE[id] = readfile(file, 2) --same but in the line 2
		end

Works

old Re: Lua Error

Jhony
User Off Offline

Quote
user sheeL has written
user Apache uwu has written
Since you don't want to load anything simply remove

1
2
3
4
5
6
7
8
9
10
11
addhook("join","save_join") -- When join load
function save_join(id)
	if player(id,"usgn") > 0 then
		local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
		local file = io.open(filename)
		if file then
			VALUE[id] = readfile(file, 1) --read a value in the line 1
			VALUE[id] = readfile(file, 2) --same but in the line 2
		end
	end
end


no no no no no @user Apache uwu: , remove the line :

1
2
3
4
if file then
			VALUE[id] = readfile(file, 1) --read a value in the line 1
			VALUE[id] = readfile(file, 2) --same but in the line 2
		end

Works


Thanks @user sheeL:
you help i
SOLVED

old Re: Lua Error

Apache uwu
User Off Offline

Quote
@user sheeL: Well since there is nothing else in the join hook it is much better just to remove all of it. Less hooks = faster and more efficient.

old Re: Lua Error

sheeL
User Off Offline

Quote
user Apache uwu has written
@user sheeL: Well since there is nothing else in the join hook it is much better just to remove all of it. Less hooks = faster and more efficient.


He did not want to read a file (read out, what's inside the file)
he only wants USGN is run when the player enters the server
@user Apache uwu: understand?
sorry for my english

~~
1
2
3
4
5
6
7
addhook("join","save_join") -- When join load
function save_join(id)
     if player(id,"usgn") > 0 then
          local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
          local file = io.open(filename)
     end
end

Line Deleted
1
2
VALUE[id] = readfile(file, 1) --read a value in the line 1
               VALUE[id] = readfile(file, 2) --same but in the line 2
edited 1×, last 21.04.12 01:28:54 am

old Re: Lua Error

Apache uwu
User Off Offline

Quote
Well if you look closely at the join hook it does nothing but read 2 values. Since you don't need to read anything, or check if the file exists you can remove it all together.

old Re: Lua Error

sheeL
User Off Offline

Quote
user Apache uwu has written
Well if you look closely at the join hook it does nothing but read 2 values. Since you don't need to read anything, or check if the file exists you can remove it all together.


Further loading of the players USGN
we must gain a hook "join" to do this
to delete everything, it would be necessary to change a map
to load
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview