Legacy GM Partial Array name with variable

balmut

Member
Hi guys sorry to bother you all, I've been googling round for a solution to this but without any luck.

What I'm trying to do is reduce the amount of code needed by using an array of values instead of several if statements.

I have a couple different arrays with similar names (aType, bType, cType), I want to be able to call the correct array using a Variable. Using draw something like this looks right but it doesn't seem to reference the array in practice;

So name could = a or b or c

Code:
var t = (string(name) + "Type");

var r;
for (r = 0; r <array_length_id(t); r+=1){
array = t[r];
}
so if name = a, it should output aType[r]. If b = bType[r] etc...



Any and all help would be greatly appreciated :)
Thanks!
 
M

montiedragon

Guest
To my knowledge, there is no way to do this. If I remember correctly there used to be functions for this "variable_local_array_get" and "variable_local_array_get" but they were removed. I would suggest looking into data structures and Accessors(maps and lists in particular). They may help with something similar if you store the lists in the map using a key.
 

balmut

Member
To my knowledge, there is no way to do this. If I remember correctly there used to be functions for this "variable_local_array_get" and "variable_local_array_get" but they were removed. I would suggest looking into data structures and Accessors(maps and lists in particular). They may help with something similar if you store the lists in the map using a key.
Hmm, well that's not good! I'll definitely look into lists. The reason I thought it was possible was because I used something similar to get partial sprite_index names from an array (using asset_get_index)

Code:
sprite_index = asset_get_index("a"+string(Type));
 

Yal

šŸ§ *penguin noises*
GMC Elder
You could use ds_maps instead of arrays - you can access them with both string keys and real keys.
 
Top