• 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!

GameMaker how to make object remember collisions?

D

dannyjenn

Guest
My initial thought process is to have the attack_range_obj keep track of every enemy it hits, and to check to see if it has already hit an enemy before carrying out the damage script. But like I said I am having the darnest time figuring out how to make that work. Any input you can provide would be greatly appreciated.
I think that could work.

To do that, you'd use a ds_list. Look these functions up in the help file (F1):
ds_list_create()
ds_list_add()
ds_list_find_index()
ds_list_destroy()

You basically need to do something like this:
Code:
// attack_range_obj create event:
enemies = ds_list_create();
Code:
// attack_range_obj collision with enemy_obj:
if(ds_list_find_index(enemies,other.id)==-1){
    // do the damage
    ds_list_add(enemies,other.id);
}
Code:
// attack_range_obj destroy event:
ds_list_destroy(enemies); // <-- do not forget this line!
 

Joe Ellis

Member
You can use ds_list, or just arrays,
arrays are the best, but you have to make your own scripts for complex stuff, but youve got way more control over everything with arrays but you have to do it all yourself
ds functions are basically arrays, but if you ever feel like your too limited with ds stuff, you can do all the same stuff with arrays plus anything else you can think of
 
Top