Forum

> > CS2D > Scripts > LUA question - add to table
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch LUA question - add to table

13 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt LUA question - add to table

Infinite Rain
Reviewer Off Offline

Zitieren
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~

alt Re: LUA question - add to table

Yasday
User Off Offline

Zitieren
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.

alt Re: LUA question - add to table

MrShock
User Off Offline

Zitieren
Yates hat geschrieben
Yes, I know. But he just failed and said dumass.


Yeah.

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

alt Re: LUA question - add to table

BrahOrkah
BANNED Off Offline

Zitieren
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
4× editiert, zuletzt 16.04.11 16:45:51

alt Re: LUA question - add to table

Yasday
User Off Offline

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

Yates hat geschrieben
If I'm not mistaken {} is a table?

It is.

alt Re: LUA question - add to table

KimKat
GAME BANNED Off Offline

Zitieren
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.

alt Re: LUA question - add to table

Starkkz
Moderator Off Offline

Zitieren
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

alt Re: LUA question - add to table

Banaan
User Off Offline

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