Forum

> > CS2D > Scripts > LUA ERROR: sys/lua/test2.lua:12: attempt to index
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

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

4 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

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

DX
User Off Offline

Zitieren
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
2× editiert, zuletzt 17.01.21 20:50:38

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

DC
Admin Off Offline

Zitieren
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.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht