Forum

> > CS2D > Scripts > Error with table
Forums overviewCS2D overview Scripts overviewLog in to reply

English Error with table

2 replies
To the start Previous 1 Next To the start

old Error with table

Kel9290
User Off Offline

Quote
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?
edited 1×, last 07.08.11 08:36:56 pm

old Re: Error with table

Lee
Moderator Off Offline

Quote
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))
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview