K
Kuro
Guest
Hi, how are you all today?
tl;dr version:
Is there a way to let a created object know which instance created it, so i can keep it aligned with its creator's x,y, (to do the x,y, matching in the created object's code rather than doing this alignment in the creating object's code)?
Long version:
I've made an object that represents an enemy's mele attack which my enemies can spawn at their x, y coords should my player obj get within their attack range if they feel like attacking (the attack object will then be used to check for collisions with player). The attacking object has creation code that sets an alarm that will clean it up after a short duration.
I'd quite like for the attack object to be able to match the x,y of the enemy object that created it, so that if the enemy moves forward the attack object will move forward as well. But I'm not quite sure how I would pass that info to it.
right now in the creator code I tried storing the created object in a temp variable called atk, then using atk.calling_enemy = self; to try to pass the id of the creator to the created object, but it's throwing an error.
Code in the enemy object that creates the attack object
code in the attack object
Id kind of like to have the attack object keep itself aligned with the enemy that created it rather than have the enemy do it, but if there's no way to pass that info to the created object I guess I could let the enemy steer its attack object around instead.
Thanks in advance for taking the time to read ths at this and for suggestions.
PS.
here's the error if I try to pre-initialize calling_enemy in the created objects create script.
---
FATAL ERROR in
action number 1
of Create Event
for object obj_pfEnemyAttack:
Variable obj_pfEnemyAttack.null(100041, -2147483648) not set before reading it.
at gml_Object_obj_pfEnemyAttack_Create_0 (line 4) - calling_enemy = null;
--
and here's the error if I comment out calling_enemy = null; in the creation code
--
FATAL ERROR in
action number 1
of Step Event0
for object obj_pfEnemyAttack:
Variable obj_pfEnemyAttack.null(100042, -2147483648) not set before reading it.
at gml_Object_obj_pfEnemyAttack_Step_0 (line 4) - if(calling_enemy != null)
--
tl;dr version:
Is there a way to let a created object know which instance created it, so i can keep it aligned with its creator's x,y, (to do the x,y, matching in the created object's code rather than doing this alignment in the creating object's code)?
Long version:
I've made an object that represents an enemy's mele attack which my enemies can spawn at their x, y coords should my player obj get within their attack range if they feel like attacking (the attack object will then be used to check for collisions with player). The attacking object has creation code that sets an alarm that will clean it up after a short duration.
I'd quite like for the attack object to be able to match the x,y of the enemy object that created it, so that if the enemy moves forward the attack object will move forward as well. But I'm not quite sure how I would pass that info to it.
right now in the creator code I tried storing the created object in a temp variable called atk, then using atk.calling_enemy = self; to try to pass the id of the creator to the created object, but it's throwing an error.
Code in the enemy object that creates the attack object
Code:
if(can_attack && !attacking)
{
attack_timer -= 1;
if(attack_timer <= 0)
{
//Mele Attack
var atk = instance_create_layer(x,y,"Actor_adds",obj_pfEnemyAttack);
atk.calling_enemy = self;
attacking = true;
alarm_set(1,atk.time_till_end);
attack_timer = attack_cooldown;
}
}
code in the attack object
Code:
//Create Event Code
calling_enemy = null;
number_of_frames = 7;
time_till_end = 30;
alarm_set(0,time_till_end);
//Step Event Code
if(calling_enemy != null)
{
x = calling_enemy.x;
y = calling_enemy.y;
}
//Alarm 0 code
instance_destroy();
Thanks in advance for taking the time to read ths at this and for suggestions.
PS.
here's the error if I try to pre-initialize calling_enemy in the created objects create script.
---
FATAL ERROR in
action number 1
of Create Event
for object obj_pfEnemyAttack:
Variable obj_pfEnemyAttack.null(100041, -2147483648) not set before reading it.
at gml_Object_obj_pfEnemyAttack_Create_0 (line 4) - calling_enemy = null;
--
and here's the error if I comment out calling_enemy = null; in the creation code
--
FATAL ERROR in
action number 1
of Step Event0
for object obj_pfEnemyAttack:
Variable obj_pfEnemyAttack.null(100042, -2147483648) not set before reading it.
at gml_Object_obj_pfEnemyAttack_Step_0 (line 4) - if(calling_enemy != null)
--