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

4 replies
Goto Page
To the start Previous 1 Next To the start
Up
DX
User
Offline Off
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)
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
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
17.01.21 07:59:31 pm
Up
ohaz
User
Offline Off
you have never defined
proj_item
https://ohaz.engineer - Software Engineering
17.01.21 08:42:13 pm
Up
DX
User
Offline Off
@user ohaz: How to fix it?
17.01.21 09:34:47 pm
Up
DC
Admin
Offline Off
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.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
17.01.21 10:27:33 pm
Up
DX
User
Offline Off
Ok
edited 1×, last 18.01.21 04:13:10 am
To the start Previous 1 Next To the start