• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How to reference a var in an array?

B

boomie

Guest
Is there a way to store a reference to a variable inside an array?
something like:
b = 1;
a[0] = reference(b);
get_referenced_var(a[0]) += 1; //now b=2
is it possible in gm:s2?
 
B

boomie

Guest
That´s unfortunate... they are talking about big changes to gml, I hope they will add this option.
 
I

icuurd12b42

Guest
if the variable is also an array then it's possible
my_arr[0] = 10;
my_arr2[0] = arr;
doStuff(my_arr2);

///doStuff(arr)
var arr2 = argument0;
var arr = arr2[0];
arr[@0] = 0;

convoluted... simplified you can change array values with the @ accessor
my_arr[0] = 10;
doStuff2(my_arr);

///doStuff2(arr)
var arr = argument0;
arr[@0] = 0;
 
Top