Forum

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

Englisch How to add table.....

8 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt How to add table.....

ratratrat
User Off Offline

Zitieren
I want to know how to add a table to a table e.e

EX:
Spoiler >





Help plz

alt Re: How to add table.....

Starkkz
Moderator Off Offline

Zitieren
That's wrong. try this way

1
2
herp = {}
herp[1] = {name="lol"}

Or

1
2
herp = {}
table.insert(herp, 1, {name="lol"})

alt Re: How to add table.....

ratratrat
User Off Offline

Zitieren
I mean like :


addhook("killobject","lalala")
function lalala(id)
table.insert(inventory[id],ITEMNUMBER = {name=hand,q=2})
end

then the player inventory will be like this:

inventory[id] = {ITEMNUMBER = {name=hand,q=2}}

alt Re: How to add table.....

EngiN33R
Moderator Off Offline

Zitieren
table.insert is more expensive.

1
2
3
4
5
6
7
8
9
10
11
-- One way of doing it
tbl = {}
tbl[1] = {name="ODIN'S BEARD"}

tbl = { --I personally prefer tihs
	[1] = {
		name = "ODIN'S BEARD",
	}
}

table.insert(tbl,{name="ODIN'S BEARD"}) --more expensive than the variants listed above and really, not as convenient

alt Re: How to add table.....

ratratrat
User Off Offline

Zitieren
OK... but i got a error , when i say "!i" (without " )

addhook("say","check")
function check(id,txt)
if txt == "!i" or txt == "!I" then
InventoryZ = Inventory[id]
for v, ALL in pairs(InventoryZ) do
msg2(id,"Inventory = "..ALL.Name.." ["..ALL.q.."]")
end
end
end

it dont show the items

EDIT:
i mean, if i add a item in the script it show but if player get a item dont show this item

PS: sry for bad english
1× editiert, zuletzt 31.05.12 03:53:18

alt Re: How to add table.....

Apache uwu
User Off Offline

Zitieren
It depends if the table is set or dynamic. If it is set it would be more efficient and more pleasing to the eye just to use:

1
2
3
4
5
herp={
	[1]={
		["name"]="lol"
	}
}

name="lol" also works, but it's a good idea to get used to using ["name"] because when you have a space you must use [""].

alt Re: How to add table.....

EngiN33R
Moderator Off Offline

Zitieren
@user ratratrat: Show us how you define your table.

user Apache uwu is right, however in my mind, if you have a string index without spaces, simply writing it is more eye candy than enclosing it in [""]. If it does have spaces however, you should do that.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht