Forum

> > CS2D > Scripts > LUA question - add to table
Forums overviewCS2D overview Scripts overviewLog in to reply

English LUA question - add to table

13 replies
To the start Previous 1 Next To the start

old LUA question - add to table

Infinite Rain
Reviewer Off Offline

Quote
I have a question:
How I can add in table
1
lol = {}
number what I say for example:

1
2
3
if I say 'add 136' then
	add.to.table 'lol' number '136'
end
cna someone help me please?

~thanks - factis699~

old Re: LUA question - add to table

Yasday
User Off Offline

Quote
I think he wants to know how to delete a value from a table.
1
table.remove(table[, position]) -- If the position isn't given, the last object of the table will be removed.
Edit:
I'm so slow with my iPod -.-'.
Btw, it's dumbass ( isn't it? ) and Yates is none of them.

old Re: LUA question - add to table

MrShock
User Off Offline

Quote
Yates has written
Yes, I know. But he just failed and said dumass.


Yeah.

By the way, What do you mean by saying "Add to table", factis ?

old Re: LUA question - add to table

BrahOrkah
BANNED Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
lol = {}

addhook("say","say1")
function say1(id,message)
	local s = message:match("add '(.*)'")
	if s ~= nil then
		local b = tonumber(s)
		if b ~= nil then
			table.insert(lol,b)
		end
	end
end
edited 4×, last 16.04.11 04:45:51 pm

old Re: LUA question - add to table

Yasday
User Off Offline

Quote
You need to use #lol + 1, or it'll overwrite the last value of the table.

Yates has written
If I'm not mistaken {} is a table?

It is.

old Re: LUA question - add to table

KimKat
GAME BANNED Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
lol = {nil,[1] = {[a] = nil}}

function IndexValue()
if lol[1][a] = nil then
	lol[1][a] = 136
else
	lol[0] = 136
end

addhook("roundstart","startround")
function startround()
	IndexValue()
end
I hope this Lua script work. In theory it should index the value 136 into the sub-table a. If that will fail to complete it will do alternative assigned indexing to the first value which is nil of the table. But perhaps error will occur, most likely it will.

old Re: LUA question - add to table

Starkkz
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
lol = {}

addhook("say","onSay")
function onSay(id,txt)
	local _txt = string.sub(txt,1,3)
	local _number = string.sub(txt,5)
	if _txt == "add" and not _number == "" then
		_number = toumber(_number)
		table.insert(lol,_number)
	end
end

old Re: LUA question - add to table

Banaan
User Off Offline

Quote
KimKat7 has written
1
lol = {nil,[1] = {[a] = nil}}


As Yasday said, that should either be
1
lol = {nil, [2] = {["a"] = nil}}

or
1
lol = {nil, [2] = {a = nil}}

Furthermore, I changed the subtable to the second index for it'd be rather useless otherwise (as Yasday explained)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview