• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

GML Fixing delay between script sending signal and object receiving signal? [SOLVED]

Dr_Nomz

Member
I have a script that sends a signal to an object to tell it to update it's variable, and the object, if it collides with something, damages the thing it hit.
Code:
scr_Melee_Collision(x+lengthdir_x(0,angle_1+90),y+lengthdir_y(0,angle_1+90),x+lengthdir_x(punch_length_1,angle_1),y+lengthdir_y(punch_length_1,angle_1))
That's in my player object's draw event, it creates a line that if it collides, it activates a script:
Code:
var collide_close = scr_Collision_Line_First(argument0,argument1,argument2,argument3,par_Bullet_Collision,true,false);

if (instance_exists(collide_close)){
if debug_message_bullet_collision == true{
show_debug_message("I collided with something")
show_debug_message(object_get_name(collide_close.object_index))}
//  if (instance_exists(collide_far)){show_debug_message("I collided with something")}
if collide_close.object_index == obj_Wall ||
object_is_ancestor(collide_close.object_index,obj_Wall){
  with par_Melee{ collision = 0; }
  instance_create(collide_close.x,collide_close.y,obj_Hit_Detector_1);
  //instance_destroy(self);

  exit;
}else
if collide_close.object_index == par_Enemy ||
object_is_ancestor(collide_close.object_index,par_Enemy){
  //with(collide_close){ scr_Enemy_Damage(argument0); }
  with par_Melee{ collision = 1; }
  //instance_create(collide_close.x,collide_close.y,obj_Hit_Detector_2);
  //instance_destroy(self);
  exit;
}else{
  with par_Melee{ collision = 1; }
}
}
This script uses collision line to check if there's an enemy or a wall near it, and if there's nothing, collision will be 1, so that if the object's hitbox hit's something, it damages it.
Code:
//Create Event
attack = 1;
collision = 0;
//Step Event
var collision_enemy = instance_place(x,y,par_Enemy);
if collision_enemy && attack == 1 && collision == 1{
  with collision_enemy{
    instance_create(collision_enemy.x,collision_enemy.y,obj_Hit_Detector_2);
    scr_Enemy_Damage(obj_Punch_1);
  }
  attack = 0;
}
This is the projectile (or melee) object's code. If attack is lower than 1, it can't damage another enemy. If collision is lower than 0, it won't damage anything.

What I want it to do is check for a collision, and if there's an enemy closer to it than a wall, it'll damage it, but not if the enemy is behind a wall. However I want this all to take place during the frame it's happening, not the frame after or it won't work. Is there any way to fix this?

The issue is if the script finds a collision, the melee object won't update and damage the enemy (or not if there's a wall) until the NEXT frame.
 

Slyddar

Member
Well firstly, Yoyo always recommend unless it's actually drawing, don't do it in a draw event.
Secondly, you could utilise the begin and end step events if you want things to happen in the same step.
 

Dr_Nomz

Member
That was actually a good idea, and putting most of the necessary code into the draw_end event of the projectile worked great. Thank you.
 
Top