Jump to content

Simple Lua Misunderstanding


GhostXoP

Recommended Posts

Posted

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 

Posted

To be honest, I didn't understand anything of what you're confused about.. Now, I'm confused.

Posted

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 

Posted (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.

2n0v3vp.png

Edited by Guest
Posted

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)  

Posted

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

Posted
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.

Posted

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.

Posted

I understood once you got it "fixed". Your "Simple Lua Misunderstanding" became "Unbelievably hard to understand question"..

Posted

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 = { } 

Posted
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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...