Page 1 of 1

Can i send reference to a variable to a function?

Posted: Wed Jan 13, 2016 9:16 pm
by Bugala
Here is what i am trying to achieve: (wrong example)

table.variable

function myfunc(func_variable)
func_variable = 1
endfunction


myfunc(table.variable)



What happens now is that when i access myfunc function, it is sending a value. A value that is on "table" at item "variable".
When i in function change that func_variable, it is simply changing the value of a independent copy of that value to 1.


What I would like to happen is, that when i change this value to 1, it would be affecting the value of the "table.variable" to become 1.

Therefore it seems to me like a good solution would be to send a reference of table.variable to that function, in which case it would indeed be changing table.variable to become 1, instead of independent variable,

But is it possible somehow to send a reference to a table item as one of the parameters?

Re: Can i send reference to a variable to a function?

Posted: Wed Jan 13, 2016 9:58 pm
by Bugala
Just pointing out that i do have a way around this problem, mainly sending both table and variable as separate info to the function and that way being able to do what i intend to, but it would be simpler if i would only need to send the reference to that variable inside a table.

Re: Can i send reference to a variable to a function?

Posted: Thu Jan 14, 2016 8:28 pm
by airsoftsoftwair
No, that's not possible. Just pass the table and modify the table member inside the function. Then it will automatically change in all table instances.