I'm a bit stumped here, trying to build up a table of strings and then convert them to numbers based on another table I've pre-defined.
This isn't exactly what I'm doing, but an illustration:
the "dictionary" table: (within script entity "theScript")
G = {arrow = 5, rock = 3}
If I type in console:
print(theScript.G.arrow)
I get
5
which is correct, theScript being the script entity, G being the table, and arrow being the key to value 3
I can also type in:
print(theScript.G["arrow"])
and I still get
5
which the alternate way, fine.
So my champion is carrying an arrow and a rock and I have a function in a script to search his whole inventory. When it find the arrow and the rock it adds their names to a table:
T = {}
table.insert(T,item.name)
and at the bottom of the search inventory function I have
for i=1,#T do print(T) end
and when I run the function it prints
arrow
rock
which is correct
So here's the problem, I can't get it to print an item from table T in terms of table G.
If I add this at the end of the search inventory function
for i=1,#T do print(g.T) end
and run the function it prints
nil
nil
??? why?
I tried:
for i=1,#T do local b=T print(g.b) end
but no luck, still the nil nil
I tried
for i=1,#T do local b=T print(g.) end
but then get script error '<name>' expected near '['
How can I do this???
advanced table HELP! how to reference key pairs from table 2
advanced table HELP! how to reference key pairs from table 2
Finished Dungeons - complete mods to play
Re: advanced table HELP! how to reference key pairs from tab
holy cow I was so close!
ANSWER
for i=1,#T do local b=T print(g) end
works beautifully! prints:
5
3
And the local isn't needed, as this works too:
for i=1,#T do print(g[T]) end
never tried nesting brackets like that!
ANSWER
for i=1,#T do local b=T print(g) end
works beautifully! prints:
5
3
And the local isn't needed, as this works too:
for i=1,#T do print(g[T]) end
never tried nesting brackets like that!
Finished Dungeons - complete mods to play