Twistir
|
  |
| Joined: 19 Nov 2009 |
| Total Posts: 12374 |
|
|
| 25 Jan 2015 12:11 AM |
This is suppose to print how many items are in the table, but it prints 0. What is wrong?
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}, }
print(#shirtids)
|
|
|
| Report Abuse |
|
|
Ojia
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 650 |
|
|
| 25 Jan 2015 12:18 AM |
| I think its confused because there's multiple tables in tables |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2015 12:20 AM |
| You can't have a table in a table. |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 25 Jan 2015 12:21 AM |
its no longer a table
http://wiki.roblox.com/index.php?title=Dictionary#Dictionaries |
|
|
| Report Abuse |
|
|
Twistir
|
  |
| Joined: 19 Nov 2009 |
| Total Posts: 12374 |
|
| |
|
Ojia
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 650 |
|
|
| 25 Jan 2015 12:29 AM |
| Try doing print(shirtids) instead |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 25 Jan 2015 12:31 AM |
something like this:
local count = 0 for i,v in pairs(shirtids)do count = count + 1 print(count) end
thats not a very good one but ill leave it to you to refine it |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2015 01:09 AM |
The # operator doesn't work with dictionaries, only with standard tables, which have numeric keys. You'll need to write a custom function to retrieve the amount of values inside.
function _(t) i=0; k,v = next(t,nil); while k do i = i+1; p = k; k,v = next(t,p); end; end;
USAGE :
print(_(shirtids));
::_::goto_ |
|
|
| Report Abuse |
|
|