GhostXoP Posted December 2, 2012 Share Posted December 2, 2012 I have a table within an array. The array is pointed to through a number so array[386] = {array variables} Example. So lets say my function recieves an argument like function(array[386]) how would i place the argument While within the function, within another array but still be able to access it doing otherarray[386] = { array variables } I can rephrase if you don't understand what im getting at I ask because i assume otherarray[argument] = argument wont keep it so i can do otherarray[386] = original data Link to comment
50p Posted December 2, 2012 Share Posted December 2, 2012 To be honest, I didn't understand anything of what you're confused about.. Now, I'm confused. Link to comment
GhostXoP Posted December 2, 2012 Author Share Posted December 2, 2012 Lets say you have an array, which contains a sub array, which contains a variable. To get to the variable, you must do THEArray[386].Variable = "hello" Now, lets say you have a function, it takes an argument of an array and puts this array within another array. function ArrayCombiner(array,NEWsubarray) array[NEWsubarray] = NEWsubarray end this would put NEWsubarray within array. local tempArray If we did ArrayCombiner(tempArray,THEArray[386]) this would put 386 array within tempArray now my question is, how can i do this, merging values and keep the reference name of 386? if i do this, and then did print(tempArray[386].Variable) it doesnt exist. Ofcourse, i know this doesnt work. My point is to show you what i want to do, and figure out if there is a way of doing this, and keeping the name 386. so i can do tempArray[386].Variable Link to comment
Renkon Posted December 2, 2012 Share Posted December 2, 2012 tempArray = { [386] = "test" } ? Link to comment
GhostXoP Posted December 2, 2012 Author Share Posted December 2, 2012 (edited) Put that in function form. Take an array and keep its value that references it. You just did an assignment, but what if you don't know the reference name? That's my problem. Edited December 2, 2012 by Guest Link to comment
Renkon Posted December 2, 2012 Share Posted December 2, 2012 You mean something like this? function addArrayIntoArray(big, small) if not big or not small then return false big[small] = small return true end -- somewhere else addArrayIntoArray(superArray, littleArray) Link to comment
GhostXoP Posted December 2, 2012 Author Share Posted December 2, 2012 I have re-edited my post for better understanding. I want to keep the number that indexes the subarray from the parent array, and when putting the subarray within another parent array, and be able to index it with the same number Link to comment
GhostXoP Posted December 2, 2012 Author Share Posted December 2, 2012 I would do key,value in pairs BUT then i assume it would do Array[key].Var and i want the actual key, not the name being key. Link to comment
Renkon Posted December 2, 2012 Share Posted December 2, 2012 function addArrayIntoArray(big, small) if not big or not small then return false big[small] = small return big end table = addArrayIntoArray(table,small) Try that. At a glimpse, I believe it didnt work because of changing values that wouldn't me modified out-side the funcion. Link to comment
GhostXoP Posted December 2, 2012 Author Share Posted December 2, 2012 Maybe your not seeing what im getting at, but i thank you for trying. I want to be able to pass arrays into a function, and combine them with another array. But lets say one array is in another array and is indexed with the number 341, i want the function to put the array into another array, but still be able to access the sub array by doing array[341]. I want to put arrays into other arrays and keep their indexes. I know they are merging, but i still want to keep how you access them. So if you could access array[2].hey, using the function i want, you would get anotherarray[2].hey I want to keep the KEY VALUE. Link to comment
GhostXoP Posted December 2, 2012 Author Share Posted December 2, 2012 I have fixed it Link to comment
50p Posted December 2, 2012 Share Posted December 2, 2012 I understood once you got it "fixed". Your "Simple Lua Misunderstanding" became "Unbelievably hard to understand question".. Link to comment
GhostXoP Posted December 2, 2012 Author Share Posted December 2, 2012 What i had wanted was a little difficult to explain. Link to comment
myonlake Posted December 2, 2012 Share Posted December 2, 2012 I don't get why you were trying to do the array like in Java or C. As far as I know, I don't think you are able to make predefined lengths for arrays like so in LUA.. array[100] = { } array = { } Link to comment
50p Posted December 2, 2012 Share Posted December 2, 2012 I don't get why you were trying to do the array like in Java or C. As far as I know, I don't think you are able to make predefined lengths for arrays like so in LUA.. array[100] = { } array = { } That's not what he was after. He wanted to access table inside a 2 tables with the same index. With his code a "sub-table" from table1 at specific index will be assigned to table2 at the same index. 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