Quick table question (keys)..

What am I missing here, I could have sworn this was supposed to work:

[lua]guid = {};
guid.used = {};

local currentGuid = ‘8477CFBA-F15C-EFEC-D155-6646D326B3B2’;
guid.used[currentGuid] = currentGuid;
print(#guid.used); – Says 0[/lua]

Thanks! [import]uid: 19193 topic_id: 21277 reply_id: 321277[/import]

Hi Scott,

Maybe this will help…

guid = {};  
guid.used = {};  
   
local currentGuid = '8477CFBA-F15C-EFEC-D155-6646D326B3B2';  
guid.used[currentGuid] = currentGuid;  
print(#guid.used[currentGuid]); -- Says 0 \*\*\*\*\* this it the length of what's in there  
print("what is it: keyed with currentGuid ", guid.used[currentGuid]);  
guid.used[0] = currentGuid;  
print("What is it: keyed with 0 ", guid.used[0]);  
  

Hope that helps ya a little…
Happy Coding…:slight_smile:
Larry
[import]uid: 107633 topic_id: 21277 reply_id: 84265[/import]

Scott, you need to read up on how tables work in Lua. Because you have set the

local currentGuid = '8477CFBA-F15C-EFEC-D155-6646D326B3B2';  
guid.used[currentGuid] = currentGuid;  
print(#guid.used); -- Says 0  

an item in the table/array as a named index, currentGuid, the table will not return the length and will return 0.

you can read up more on tables at these links

http://howto.oz-apps.com/2011/09/if-i-were-carpenter-would-you-buy-my.html

http://howto.oz-apps.com/2011/09/tables-part-2.html

and for more tutorials you can visit my blog at howto.oz-apps.com
[import]uid: 3826 topic_id: 21277 reply_id: 84303[/import]