Yeah, as
@Nidoking said, you're thinking of it in the wrong context. Simply assigning a variable to another variable does literally nothing to make either accessible from the other. What you want is a list or a map that you can reference for each thing, with the values in that list or map representing different things you might want to read or change. An example would be a list of enemies. The naive way of thinking about it is to assign an instance ID to each list position, i.e.:
Code:
// Enemy list creation
enemy_list = ds_list_create();
// Enemy 1 store
enemy_list[| 0] = instance_create_layer(x,y,layer,obj_enemy1);
// Enemy 2 store
enemy_list[| 1] = instance_create_layer(x,y,layer,obj_enemy1);
// Enemy 3 store
enemy_list[| 2] = instance_create_layer(x,y,layer,obj_enemy2);
Here we have a list of enemies, with two instances of obj_enemy1 and one instance of obj_enemy2 being stored. Without setting up specific instance variables for various values you want, literally all you can do is return the instance ID. However, if you do something like this:
Code:
// Enemy list creation
enemy_list = ds_list_create();
// Create enemy 1 map
var enemy_map = ds_map_create();
// Store enemy 1 map values
enemy_map[? "object type"] = obj_enemy1;
enemy_map[? "name"] = "Bob";
// Add enemy 1 map to enemy list
ds_list_add(enemy_list,enemy_map);
ds_list_mark_as_map(ds_list_size(enemy_list)-1);
// Create enemy 2 map
var enemy_map = ds_map_create();
// Store enemy 2 map values
enemy_map[? "object type"] = obj_enemy1;
enemy_map[? "name"] = "Jane";
// Add enemy 2 map to enemy list
ds_list_add(enemy_list,enemy_map);
ds_list_mark_as_map(ds_list_size(enemy_list)-1);
// Create enemy 3 map
var enemy_map = ds_map_create();
// Store enemy 3 map values
enemy_map[? "object type"] = obj_enemy2;
enemy_map[? "name"] = "Tarzan";
enemy_map[? "attack"] = scr_yodel;
// Add enemy 3 map to enemy list
ds_list_add(enemy_list,enemy_map);
ds_list_mark_as_map(ds_list_size(enemy_list)-1);
You can store as much information as you want about each enemy in their enemy_map, and then when you retrieve the list position for that enemy, you will be returned a map that you can then use to grab whatever values you've stored previously. In reality, the same effect can be achieved by using instance variables, but there may be some situation in which you want this kind of behaviour to be linked without having instance variables associated. This way, instead of trying to associate a global or instance variable with a specific name and then referencing that, you can just grab your enemy map and read what is in there, alongside anything else you might want to access:
Code:
//Get the name AND object type of the enemy at list position 0
var enemy_map = enemy_list[| 0];
var name = enemy_map[? "name"];
var obj_type = enemy_map[? "object type"];
You can also check if things have specific variables associated with them with a lesser CPU cost than checking if that variable exists in an instance scope for that instance (as far as I understand it):
Using the first code style I outlined, with instance variables being used instead of map keys (higher CPU cost):
Code:
var enemy_inst = enemy_list[| 0]; // Get the instance ID for the enemy in slot 0 of enemy_list
if (variable_instance_exists(enemy_inst,"attack")) {
script_execute(attack);
}
Using the second code style I outlined, with map entries being used instead of instance variables (lower CPU cost):
Code:
var enemy_map = enemy_list[| 0];
if (ds_map_exists(enemy_map,"attack")) {
script_execute(enemy_map[? "attack"]);
}
Taking the time to learn how to use lists, maps, grids, priority lists, etc, is 100% worth your development time, as you will find many varied uses for these data structures that are either harder, or impossible, to replicate using simple arrays.