English Lua Error

23 replies
Goto Page
To the start Previous 1 2 Next To the start
20.04.12 02:40:05 am
Up
Jhony
User
Offline Off
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
20.04.12 02:55:48 am
Up
oxytamine
User
Offline Off
Code:
1
for _, usgn in ipairs(sys/lua/usgns/"..player(id,"usgn")..".txt"") do

You haven't closed quotes properly. Append this fix.
Code:
1
for _, usgn in ipairs("sys/lua/usgns/"..player(id,"usgn")..".txt") do
20.04.12 03:51:47 am
Up
Jhony
User
Offline Off
user oxytamine has written:
Code:
1
for _, usgn in ipairs(sys/lua/usgns/"..player(id,"usgn")..".txt"") do

You haven't closed quotes properly. Append this fix.
Code:
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)
20.04.12 04:06:47 am
Up
oxytamine
User
Offline Off
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.
20.04.12 04:30:43 am
Up
Jhony
User
Offline Off
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)
20.04.12 04:36:15 am
Up
PyKemis
User
Offline Off
Code:
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:

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


If it's to everyone replace ID with 0:

Code:
1
2
3
if act == 1 then -- F2
          menu(0,"Menu,lol")
     end
20.04.12 04:20:37 pm
Up
Jhony
User
Offline Off
user PyKemis has written:
Code:
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:

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


If it's to everyone replace ID with 0:

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


That's not what I want
read the topic again
20.04.12 04:49:01 pm
Up
PyKemis
User
Offline Off
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.
20.04.12 05:14:36 pm
Up
Jhony
User
Offline Off
user PyKemis 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
20.04.12 05:24:57 pm
Up
PyKemis
User
Offline Off
Code:
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
20.04.12 05:48:38 pm
Up
Jhony
User
Offline Off
user PyKemis has written:
Code:
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


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
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?
20.04.12 06:21:02 pm
Up
PyKemis
User
Offline Off
Well since /usgns/89367.txt is empty,

Code:
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.
20.04.12 06:24:00 pm
Up
Jhony
User
Offline Off
user PyKemis has written:
Well since /usgns/89367.txt is empty,

Code:
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 :

Code:
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
20.04.12 06:26:52 pm
Up
PyKemis
User
Offline Off
Since you don't want to load anything simply remove

Code:
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
20.04.12 06:32:08 pm
Up
sheeL
User
Offline Off
user PyKemis has written:
Since you don't want to load anything simply remove

Code:
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 PyKemis: , remove the line :

Code:
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
20.04.12 06:33:17 pm
Up
Jhony
User
Offline Off
user sheeL has written:
user PyKemis has written:
Since you don't want to load anything simply remove

Code:
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 PyKemis: , remove the line :

Code:
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
20.04.12 06:36:54 pm
Up
PyKemis
User
Offline Off
@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.
21.04.12 01:26:20 am
Up
sheeL
User
Offline Off
user PyKemis 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 PyKemis: understand?
sorry for my english

~~
Code:
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
Code:
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
21.04.12 01:27:47 am
Up
PyKemis
User
Offline Off
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.
21.04.12 01:30:03 am
Up
sheeL
User
Offline Off
user PyKemis 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