W
whale_cancer
Guest
As part of my game's data structure I have a global list (global.markers) that holds a series of ds_maps saved as strings.
In my map editor, when I create a new one of these markers it gets added to the global list successfully (I am able to load and save the global.markers_list in an external file and they generate correctly on the map when I do).
When I create a new marker in my map editor (which is an object that holds the same data as the associated ds_map) I want to loop through the ds_list and make sure that I am not placing one with the same name as one that already exists (as this would cause problems with how I use the markers in the game itself).
Here is the relevant code for creating the marker objects:
Here is my debug output.
As you can see, rather than comparing the new name to each existing name in the list, it instead compares it to the first name in the list for as many times as there are markers. If I use the same name as the first marker in the list, it behaves as it should.
Must be some elementary mistake I am not seeing?
In my map editor, when I create a new one of these markers it gets added to the global list successfully (I am able to load and save the global.markers_list in an external file and they generate correctly on the map when I do).
When I create a new marker in my map editor (which is an object that holds the same data as the associated ds_map) I want to loop through the ds_list and make sure that I am not placing one with the same name as one that already exists (as this would cause problems with how I use the markers in the game itself).
Here is the relevant code for creating the marker objects:
Code:
with (instance_create(global.cell_hover_x, global.cell_hover_y, obj_marker))
{
temp_map = ds_map_create();
//what chunk are we in?
ds_map_add(temp_map, 'chunk', global.map_name);
//what are the w,h coordinates of the marker (relative to the chunk)?
ds_map_add(temp_map, 'w', global.cell_hover_w);
ds_map_add(temp_map, 'h', global.cell_hover_h);
//what is the name of the chunk?
name = get_string('marker name?', 'marker_'+string(ds_list_size(global.markers)));
ds_map_add(temp_map, 'name', name);
show_debug_message('---');
//check to see if a marker with this name already exists
for (i = 0; i < ds_list_size(global.markers); i += 1)
{
//convert the ds_map string at list location i back into a ds_map
temp_string = ds_list_find_value(global.markers, i);
temp_map = ds_map_create();
ds_map_read(temp_map, temp_string);
//find the thing with the same name yo
temp_name = ds_map_find_value(temp_map, 'name')
show_debug_message(string(temp_name)+' compared to '+string(name))
if (temp_name == name)
{
show_debug_message('Found marker with that name already')
ds_map_destroy(temp_map);
instance_destroy()
exit;
}
}
temp_string = ds_map_write(temp_map);
ds_list_add(global.markers, temp_string);
ds_map_destroy(temp_map);
}
Code:
---
default_start compared to marker_1
---
default_start compared to marker_2
default_start compared to marker_2
---
default_start compared to marker_3
default_start compared to marker_3
default_start compared to marker_3
---
default_start compared to default_start
Found marker with that name already
Must be some elementary mistake I am not seeing?