LUA ERROR: sys/lua/test2.lua:12: attempt to index
4 replies



17.01.21 07:36:09 pm
LUA ERROR: sys/lua/test2.lua:12: attempt to index global 'proj_item' (a nil value)
I know the problem but i dont know how to fix
I want change proj_item[id] Based on function proj_drop (id, item)
I know the problem but i dont know how to fix
I want change proj_item[id] Based on function proj_drop (id, item)
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
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 array(a)
local array = {}
for i = 1, a do
array[i]=0
end
return array
end
proj_1 = array(32)
proj_2 = array(32)
function proj_drop(id,item)
proj_item[id]=proj_item[id]+1
parse("equip "..id.." "..item)
end
addhook("say","say")
function say(id,say)
if (say=="hi") then
proj_drop(id,1)
end
end
addhook("always","aks")
function aks()
for id = 1, 32 do
parse('hudtxt2 '..id..' 1 "'..proj_1[id]..'" 10 140')
end
end
local array = {}
for i = 1, a do
array[i]=0
end
return array
end
proj_1 = array(32)
proj_2 = array(32)
function proj_drop(id,item)
proj_item[id]=proj_item[id]+1
parse("equip "..id.." "..item)
end
addhook("say","say")
function say(id,say)
if (say=="hi") then
proj_drop(id,1)
end
end
addhook("always","aks")
function aks()
for id = 1, 32 do
parse('hudtxt2 '..id..' 1 "'..proj_1[id]..'" 10 140')
end
end
edited 2×, last 17.01.21 08:50:38 pm
You should probably add a
after line 9 to define it.
The entire script in general doesn't make much sense. Is that the complete script or just a part of it?
You're displaying proj_1 using
hudtxt2 but you're never assigning a value.
Moreover you're using
always to print it which is very bad practice, causes massive traffic and can also lead to bad pings / bad overall performance.
Morever proj_2 is defined but not used at all.
proj_item = array(32)
after line 9 to define it.
The entire script in general doesn't make much sense. Is that the complete script or just a part of it?
You're displaying proj_1 using

Moreover you're using

Morever proj_2 is defined but not used at all.



