Roastedzerg
Member
I'm trying to figure out whats going wrong with the enemy pileup code i made using the list data system. It looks like it almost works, as the enemies will sorta work at first and only a couple will attack the player while the others wait, but after about 3 seconds, sometimes immediately, they are all attacking at once. My guess is they are all trying to add themselves to the attack list at the same time and overriding the limit i have set. what might i be doing wrong in my code that could be allowing this to happen?
My enemies run off a basic state system and when they are told to attack the player they use the pileup check script to see if they are allowed to attack, and if they aren't they go idle. Then, after a successful attack they find and delete their ID from the list to make room for the other enemies. Im trying to figure out how to keep the enemies from jumping into the list at the same time so the limit doesnt get passed in a single step.
Any suggestions? Let me know if i need to elaborate on anything or if something doesn't make sense so i can reword it.
Edit: I realized just now that if i could somehow figure out how to check the list size every few steps to see if its larger than the max size i could then figure out where the enemy executing the code is on the list. And if the enemy is positioned on the list past the max amount of slots on the list delete his slot. How could i go about doing this? Ill keep looking on my end.
GML:
/// @function scr_pileup_check(player_number, estate, estate backup);
/// @param {real} player_number player we are pileuping onto
/// @param {real} estate state to switch to
/// @param {real} estate backup state to switch to if we cant add id to list
function scr_pileup_check(argument0, argument1, argument2) {
if(argument0==1)
{
if(ds_exists(global.p1_pileup_list,ds_type_list))
{
var id_index_check_p1=ds_list_find_index(global.p1_pileup_list,id);
if(id_index_check_p1==-1)
{
if(ds_list_size(global.p1_pileup_list)<6){ds_list_add(global.p1_pileup_list,id);scr_state_switch(argument1);}
else{if(argument2!=noone){scr_state_switch(argument2);}}
}
else{scr_state_switch(argument1);}
}
else{return false;}
}
}
GML:
if(is_near_player)
{
if(my_target!=noone&&instance_exists(my_target))
{
scr_pileup_check(my_target.player,estate_attack_basic,estate_idle);
}
}
GML:
function scr_pileup_delete() {
if(ds_exists(global.p1_pileup_list,ds_type_list))
{
var id_index_check_p1=ds_list_find_index(global.p1_pileup_list,id);
if(id_index_check_p1!=-1)
{
ds_list_delete(global.p1_pileup_list,id_index_check_p1);
}
}
}
GML:
//If we aren't attacking the player remove our id from the pileup lists
if(state!=estate_attack_basic&&state!=estate_attack_lunge)
{
scr_pileup_delete();
}
My enemies run off a basic state system and when they are told to attack the player they use the pileup check script to see if they are allowed to attack, and if they aren't they go idle. Then, after a successful attack they find and delete their ID from the list to make room for the other enemies. Im trying to figure out how to keep the enemies from jumping into the list at the same time so the limit doesnt get passed in a single step.
Any suggestions? Let me know if i need to elaborate on anything or if something doesn't make sense so i can reword it.
Edit: I realized just now that if i could somehow figure out how to check the list size every few steps to see if its larger than the max size i could then figure out where the enemy executing the code is on the list. And if the enemy is positioned on the list past the max amount of slots on the list delete his slot. How could i go about doing this? Ill keep looking on my end.
Last edited: