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

How do make an if statement to check if a script is running?

Lightmind

Member
Basically, I have a script called PlayerState_Attack_Slash and when i press the X button, it runs the script doing an attack. How would I make an if statement in the player or enemy to detect if the enemy is colliding with the player during the attack script e.g. if (obj_player is in PlayerState_Attack_Slash) {
instance_destroy(obj_enemy)
}
 

Lightmind

Member
How would I be able to use that in an if statement to detect a collision while in that script, because what I'm trying to do is use a melee attack to hit an enemy, but they only get hit while the player is using the PlayerState_Attack_Slash script.
 

Lightmind

Member
function PlayerState_Attack_Slash(){
hsp = 0;
vsp = 0;

// Start of the attack
if (sprite_index != spr_player_atk) {
sprite_index = spr_player_atk;
image_index = 0;
ds_list_clear(hit_by_attack);
}

// Use attack hitbox and check for hits
mask_index = spr_player_atkHB;
var hitByAttackNow = ds_list_create();
var hits = instance_place_list(x, y, obj_enemy, hitByAttackNow, false);
if (hits > 0) {
for (var i = 0; i < hits; i ++) {
// If this instance has not yet been hit by this attack
var hitID = hitByAttackNow[| i];
if (ds_list_find_index(hit_by_attack, hitID) == -1) {
ds_list_add(hit_by_attack, hitID);
}
}
}


ds_list_destroy(hitByAttackNow);
mask_index = spr_player;

if (animation_end()) {
sprite_index = spr_player;
state = PLAYERSTATE.FREE;
}
canattack = false;
alarm[0] = room_speed * 0.2;
}
 
Top