Mega9 Posted March 18, 2014 Share Posted March 18, 2014 I was wondering how do I add more values to it since I need to loop the table and put the values of the right matching key in a gridlist, but when I use comma to separate more values it doesn't work and adds only the first value in gridlist. local exampleTable = { stringKey = "Value 1" } Link to comment
Mr_Moose Posted March 18, 2014 Share Posted March 18, 2014 local exampleTable = { [stringKey1] = "Value 1", [stringKey2] = "Value 2", [stringKey3] = "Value 3", } That should do the trick. Link to comment
WhoAmI Posted March 18, 2014 Share Posted March 18, 2014 exampleTable = { stringKey = "Value 1", secondString = "Value 2" } or table.insert Link to comment
Mega9 Posted March 18, 2014 Author Share Posted March 18, 2014 Sorry guys, I explained my problem really sloppy, problem was actually turning those: local exampleTable = { stringKey = "Value 1", secondString = "Value 2" } into: local exampleTable = { stringKey = "Value 1", "Value 2", "Value 3", secondStringKey = "Mike", "Micheal" } So basically, 1 key = more than 1 value/string. And then when I make it the way I just did, it loops the table, but adds only first string/value of every string key. Do you know what I mean? Sorry I haven't explained it properly in the first post. Link to comment
Mr_Moose Posted March 18, 2014 Share Posted March 18, 2014 No problem at all then, try this: local exampleTable = { [stringKey1] = { "Value 1", "value 2", "value 3" }, [stringKey2] = { "Value 1a", "value 2a", "value 3a" }, [stringKey3] = { "Value 1b", "value 2b", "value 3b" } } Multidimensional table if that's what you asked for Link to comment
Mega9 Posted March 18, 2014 Author Share Posted March 18, 2014 That's just about what I was looking for. Thank you both! Link to comment
Moderators IIYAMA Posted March 18, 2014 Moderators Share Posted March 18, 2014 @mrbrutus1467 and all who don't understand.... local exampleTable = { [stringKey1] = { "Value 1", "value 2", "value 3" }, } Now stringKey1 have to be a variable, which isn't defined. It is: local exampleTable = { stringKey1 = { "Value 1", "value 2", "value 3" } } or local exampleTable = { ["stringKey1"] = { "Value 1", "value 2", "value 3" } } or with the variable stringKey1 but defined. local stringKey1 = "stringKey1" local exampleTable = { [stringKey1] = { "Value 1", "value 2", "value 3" } } Link to comment
Mega9 Posted March 18, 2014 Author Share Posted March 18, 2014 Indeed IIYAMA, [stringKey1] = { "Value 1", "value 2", "value 3" } returned nil, but when I changed it to stringKey1 = { "Value 1", "value 2", "value 3" } it worked fine. Link to comment
Mr_Moose Posted March 18, 2014 Share Posted March 18, 2014 @IIYAMA Unlike you I expected mega9 to be smart enough to realize the fact that a undefined variable points at nil and therefore it can't be indexed. The original question was about multidimensional arrays or tables, that has nothing to do with what you can use in order to index each row, the rows doesn't even need an index either, there are many ways to solve this kind of issue in, but just because everyone doesn't use your solution doesn't mean they are idiots. @mega9 You do realize that all you did was to create a bad implemented table, index it to nil, and then change it to a regular one dimensional array like you had in the first place. [ and ] should not be used in one dimensional arrays only in multidimensional ones like in my first example. If you want a sample that works out of the box then you should specify the details in the description. Link to comment
Moderators IIYAMA Posted March 18, 2014 Moderators Share Posted March 18, 2014 @IIYAMA Unlike you I expected mega9 to be smart enough to realize the fact that a undefined variable points at nil and therefore it can't be indexed. The original question was about multidimensional arrays or tables, that has nothing to do with what you can use in order to index each row, the rows doesn't even need an index either, there are many ways to solve this kind of issue in, but just because everyone doesn't use your solution doesn't mean they are idiots.@mega9 You do realize that all you did was to create a bad implemented table, index it to nil, and then change it to a regular one dimensional array like you had in the first place. [ and ] should not be used in one dimensional arrays only in multidimensional ones like in my first example. If you want a sample that works out of the box then you should specify the details in the description. Well mister, 8 of the 10 people that use this forum(scripting section) don't understand a damn about it. Because they learn lua via mta and not via lua sites(like: http://lua-users.org/) There isn't enough information there to know what ways there are. Link to comment
Mega9 Posted March 18, 2014 Author Share Posted March 18, 2014 I've never messed with tables for big and serious stuff until now, therefore I don't know all the workarounds and ways to use them. Anyways, thanks again for the help problem is solved. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now