Forum

> > CS2D > Scripts > LUA ERROR: sys/lua/test2.lua:12: attempt to index
Forums overviewCS2D overview Scripts overviewLog in to reply

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

4 replies
To the start Previous 1 Next To the start

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

DX
User Off Offline

Quote
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)
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
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
edited 2×, last 17.01.21 08:50:38 pm

old Re: LUA ERROR: sys/lua/test2.lua:12: attempt to index

DC
Admin Off Offline

Quote
You should probably add a
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 cs2d cmd hudtxt2 but you're never assigning a value.
Moreover you're using cs2d lua hook 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.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview