Twistir
|
  |
| Joined: 19 Nov 2009 |
| Total Posts: 12374 |
|
|
| 25 Jan 2015 12:48 AM |
I desperately need to do something like this below. The problem with this is that i cant find the different items through shirtids[1]. I have been told already that it doesnt work because I cant have a table inside a table.
shirtids = { s1 = {textureid=200029202,thumbid=200029204,cost=200}, s2 = {textureid=200029202,thumbid=200029204,cost=200}, s3 = {textureid=200029202,thumbid=200029204,cost=200}, s4 = {textureid=200029202,thumbid=200029204,cost=200}, s5 = {textureid=200029202,thumbid=200029204,cost=200}, } |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2015 12:50 AM |
shirtids.s1 returns the table 's1'. These are just known as multidimensional tables.
::_::goto_ |
|
|
| Report Abuse |
|
|
Twistir
|
  |
| Joined: 19 Nov 2009 |
| Total Posts: 12374 |
|
|
| 25 Jan 2015 12:53 AM |
| okay how could I do something like #shirtids |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2015 12:59 AM |
By that, I'm assuming you are asking how to implement a loop? Well, a numeric loop can be implemented, but not in the way you'd think.
for i=1,#shirtids,1 do local ind = i-1; local k,v = next(shirtids, ind);
-- now, the table within shirtids is stored in the variable 'v'. -- perform any actions your would've done to the table. end;
::_::goto_ |
|
|
| Report Abuse |
|
|
Twistir
|
  |
| Joined: 19 Nov 2009 |
| Total Posts: 12374 |
|
|
| 25 Jan 2015 01:06 AM |
| so s1-5 is now defined as v? |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2015 01:10 AM |
Is having them be named 's1', 's2', etc. even important? You can just treat them as numerical indices as follows:
shirtids = { {textureid=200029202,thumbid=200029204,cost=200}, {textureid=200029202,thumbid=200029204,cost=200}, {textureid=200029202,thumbid=200029204,cost=200}, {textureid=200029202,thumbid=200029204,cost=200}, {textureid=200029202,thumbid=200029204,cost=200}, }
print(shirtids[1].cost); --> 200 |
|
|
| Report Abuse |
|
|
Twistir
|
  |
| Joined: 19 Nov 2009 |
| Total Posts: 12374 |
|
|
| 25 Jan 2015 01:12 AM |
| thanks blob, I always make things a little bit more complicated to the point where they dont work lol |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2015 01:13 AM |
I'd forgotten that '#' doesn't work on dictionaries, but here's a simple workaround.
local k,v = next(shirtids,nil); while k do -- do stuff to v, v being the table s1-5. k,v = next(shirtids,k); end; |
|
|
| Report Abuse |
|
|