Forum

> > CS2D > Scripts > Error with table
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Error with table

2 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Error with table

Kel9290
User Off Offline

Zitieren
I have problem with this code:

1
2
3
4
5
6
7
8
9
10
addhook("menu","menu123")
function menu123(id,ttl,btn)
if ttl:sub(1,3)=="Buy" then
	if btn == 1 then
		local g=ttl:sub(11,11)
		if something[id] >= hs[g][3] then
			...
		end
	end
end

1
if something[id] >= hs[g][3] then
This not working, but if i change
1
local g=ttl:sub(11,11)
to
1
local g=1
this works. I not know what problem.

hs is table
1
2
3
hs={{}}
hs[1]={"h1","hw1",2500,14,8,16,8}
...

someone have answer?
1× editiert, zuletzt 07.08.11 20:36:56

alt Re: Error with table

Lee
Moderator Off Offline

Zitieren
1
2
local g=ttl:sub(11,11)
print(type(g))

will print out "string", hence you must convert g into a number before indexing into a numerically keyed table.

1
local g=tonumber(ttl:sub(11,11))
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht