with (whatever)
{
if id != other.id
{
dist = point_distance(x,y, other.x, other.y);
if can see other /// not real code here obviously
{
ds_priority_add (other.dist_list, id, dist); //dist_list wants to have already been created by the checking object
}
}
}
//find nearest enemy
var nearest_enemy = instance_nearest(x, y, [Hopefully the list of objects i tell it, it can find]);
//activate enemys freeze code
nearest_enemy.batkill = 1;
//if not at enemy go to enemy
if !(x = nearest_enemy.x) && !(y = ((nearest_enemy.y)-(sprite_height+10)))
{
mp_potential_step(nearest_enemy.x,((nearest_enemy.y)-(sprite_height+10)),7,0);
} else {
//if at enemy but has no path, start path
if (x = nearest_enemy.x) && (y = ((nearest_enemy.y)-(sprite_height+10))) && (path_index = -1) && (didpath=0)
{
//setpath and stop trying to please
path_start(ph_firebat_spin,7,path_action_stop,0);
didpath = 1;
}
}
BTW- there is now a destroy/cleanup event where you should destroy/delete your data structures. It activates whenever you would want to destroy things so you don't have to have cleanup code in several different places.@the_dude_abides and @Hyomoto helped me with ds lists so you can try asking them nicely
Try (cos I'm in no means an expert on ds_list)
enemies = ds_list_create()
ds_list_add(enemies,obj_enemy1)
ds_list_add(enemies,obj_enemy2)
and so on
game_end/room_end event
ds_list_destroy(enemies)
//nearest object
inst = instance_nearest(xx,yy, ds_list_find_value(enemies,ds_list_size(enemies)-1)
@hogwater it's either room_end/ or game_end. Room end is usually best (for me) when I have a levelled game and Game_end when it's an endless game or a game where I only need the same ds lists throughoutBTW- there is now a destroy/cleanup event where you should destroy/delete your data structures. It activates whenever you would want to destroy things so you don't have to have cleanup code in several different places.
enemies = ds_list_create()
ds_list_add(enemies,obj_skeletion)
ds_list_add(enemies,obj_slime)
//nearest object
inst = instance_nearest(x,y, (ds_list_find_value(enemies,ds_list_size(enemies)-1)));
Yeah, but no...it doesn't work like that All the instances of those enemies either need to be looped through and have their id's put into the ds_list, or you can do it like this:so I did this:
enemies = ds_list_create()
ds_list_add(enemies,obj_skeletion) // <<<< obj_skeleton!
ds_list_add(enemies,obj_slime)
with (obj_skeleton)
{ds_list_add(other.enemies, id);}
with (obj_slime)
{ds_list_add(other.enemies, id);}
with (obj_skeleton)
{if id != other
{ds_list_add(other.enemies, id);}}
with (obj_skeleton)
{
var dist = point_distance(x,y, other.x, other.y);
ds_priority_add (other.dist_list, id, dist);
}
with (obj_slime)
{
var dist = point_distance(x,y, other.x, other.y);
ds_priority_add (other.dist_list, id, dist);
}
if ds_priority_size(dist_list) > 0
{inst = ds_priority_find_min}
Right- but the destroy event : https://docs.yoyogames.com/source/dadiospice/000_using gamemaker/events/destroy event.html@hogwater it's either room_end/ or game_end. Room end is usually best (for me) when I have a levelled game and Game_end when it's an endless game or a game where I only need the same ds lists throughout
enemies = ds_list_create()
ds_list_add(enemies,obj_skeletion)
ds_list_add(enemies,obj_slime)
dist = ds_priority_create();
with (obj_skeletion)
{
var dist = point_distance(x,y, other.x, other.y);
ds_priority_add (other.dist_list, id, dist);
}
with (obj_slime)
{
var dist = point_distance(x,y, other.x, other.y);
ds_priority_add (dist_list, id, dist);
}
if ds_priority_size(dist_list) > 0
{inst = ds_priority_find_min(dist)}
@hogwater whatever works for you. As long as it works, its okRight- but the destroy event : https://docs.yoyogames.com/source/dadiospice/000_using gamemaker/events/destroy event.html
covers room_end, game_end etc all in one spot.
mm hmm - calling the priority queue 'dist' when you created it, and having it referred to as 'dist_list' when the other objects are trying to put their information into it...see if you can spot a problem there When you realize what doesn't match you will understand why you get an error.and I get <unknown_object>.<unknown variable>(100055, -2147483648) not set before reading it.Code:enemies = ds_list_create() ds_list_add(enemies,obj_skeletion) ds_list_add(enemies,obj_slime) dist = ds_priority_create(); with (obj_skeletion) { var dist = point_distance(x,y, other.x, other.y); ds_priority_add (other.dist_list, id, dist); } with (obj_slime) { var dist = point_distance(x,y, other.x, other.y); ds_priority_add (dist_list, id, dist); } if ds_priority_size(dist_list) > 0 {inst = ds_priority_find_min(dist)}
at gml_Script_scr_findenemy (line 10) - ds_priority_add (other.dist_list, id, dist);
if ds_priority_size(dist_list) > 0
{inst = ds_priority_find_min(dist);
ds_queue_clear(dist);}
dist_list = ds_priority_create();
//with (obj_skeletion)
if instance_exists(obj_skeletion)
{
//save a found skeleton with unique id
var found_skeleton = obj_skeletion.id;
//save that unique skele with its dist from bat
var dist = point_distance(x,y, found_skeleton.x, found_skeleton.y);
//throw it into the ds_priority
ds_priority_add (dist_list, found_skeleton, dist);
}
//with (obj_slime)
if instance_exists(obj_slime)
{
var found_slime = obj_slime.id;
var dist = point_distance(x,y, found_slime.x, found_slime.y);
ds_priority_add (dist_list, found_slime, dist);
}
//set inst as the closest found thing
if ds_priority_size(dist_list) > 0
{inst = ds_priority_find_min(dist_list)}
with obj_skeletion {
var dist = point_distance(x,y, other.x, other.y);
ds_priority_add(dist_list, id, dist);
}
[USER=28930 said:@EvanSki[/USER] This ain't a coding language where you need to preprend object indexes or instance ids to every variable. I'll only address your skeleton code because you made the same mistakes for the slime too.
with (obj_skeletion)
you actually want with() here, dunno why you got rid of it
if instance_exists(obj_skeletion)
this conditional is inherent inside with()
var found_skeleton = obj_skeletion.id;
this gets the id of one and only one skeleton, not all of them
this line is also pointless if you use with()
var dist = point_distance(x,y, found_skeleton.x, found_skeleton.y);
contrary to your suspicions, this would have been okay if you didn't foul up the previous line
ds_priority_add (dist_list, found_skeleton, dist);
this line is correct
As I said, you can and should use with() in this case. Furthermore, you'd make things a lot simpler if you made the slime and skeleton children of the same parent object (but that's just to save you coding space, it's not necessary).
And that's all you need to do for the skeleton. If you had a parent object, you'd replace obj_skeleton with the parent object and that would make those 3 lines of code apply to ALL enemies that are children of that parent object.Code:with obj_skeletion { var dist = point_distance(x,y, other.x, other.y); ds_priority_add(dist_list, id, dist); }
dist_list = ds_priority_create();
with obj_skeletion {
var dist = point_distance(x,y, other.x, other.y);
ds_priority_add(dist_list, id, dist);
}
with obj_slime {
var dist = point_distance(x,y, other.x, other.y);
ds_priority_add(dist_list, id, dist);
}
//set inst as the closest found thing
if ds_priority_size(dist_list) > 0
{inst = ds_priority_find_min(dist_list)}
okay so now it works perfectly!Oh, I forgot to put other. before dist_list.
ds_priority_add(other.dist_list, id, dist);
dist_list = ds_priority_create();
with obj_skeletion {
var dist = point_distance(x,y, other.x, other.y);
ds_priority_add(other.dist_list, id, dist);
}
with obj_slime {
var dist = point_distance(x,y, other.x, other.y);
ds_priority_add(other.dist_list, id, dist);
}
//set inst as the closest found thing
if ds_priority_size(dist_list) > 0
{inst = ds_priority_find_min(dist_list)}