Forum

> > CS2D > Scripts > How to add table.....
Forums overviewCS2D overview Scripts overviewLog in to reply

English How to add table.....

8 replies
To the start Previous 1 Next To the start

old How to add table.....

ratratrat
User Off Offline

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

EX:
Spoiler >





Help plz

old Re: How to add table.....

Starkkz
Moderator Off Offline

Quote
That's wrong. try this way

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

Or

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

old Re: How to add table.....

ratratrat
User Off Offline

Quote
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}}

old Re: How to add table.....

EngiN33R
Moderator Off Offline

Quote
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

old Re: How to add table.....

ratratrat
User Off Offline

Quote
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
edited 1×, last 31.05.12 03:53:18 am

old Re: How to add table.....

Apache uwu
User Off Offline

Quote
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 [""].

old Re: How to add table.....

EngiN33R
Moderator Off Offline

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