K
Krenzathal77
Guest
What's the best way for an instance/object to reference the instance that created it and then store that as a variable, but without doing it via checking for a collision or which one is nearest?
I have an enemy instance which creates an instance of a hit object and I want it to follow the enemy instance in the air and if it moves left or right. The moving bit is fine, but I keep running into problems tying to store the ID.
I've been using the usual ways to store instance ids such as -
var (enemyid) = instance_place( x , y , obj_enemy )
This doesn't work because in the game (and for this particular move) the enemy instance has no mask or bounding box (it's a deliberate gameplay choice).
var (enemyid) = instance_nearest( x , y , obj_enemy )
This works some of the time but can return an error quite a lot for some reason.
I even tried the var (enemyid) = instance_nearest( x , y , obj_enemy ) in the hit object's create event so that it would grab the nearest enemy instances ID and then I stored that in a permanent variable called EID (enemyid = EID) but that doesn't work either.
Surely there must be some way for an instance to check the id number of whatever other instance created it at the point of creating and then store that?
I know you can store the id of whatever instance is being created by the creating instance, using instance_create (there's a tongue twister) but what about the other way around?
Anyway any help would be great. I'm using GM:S 1.4, Win 7, and the code I'm trying to get to work is below.
In STEP event -
I have an enemy instance which creates an instance of a hit object and I want it to follow the enemy instance in the air and if it moves left or right. The moving bit is fine, but I keep running into problems tying to store the ID.
I've been using the usual ways to store instance ids such as -
var (enemyid) = instance_place( x , y , obj_enemy )
This doesn't work because in the game (and for this particular move) the enemy instance has no mask or bounding box (it's a deliberate gameplay choice).
var (enemyid) = instance_nearest( x , y , obj_enemy )
This works some of the time but can return an error quite a lot for some reason.
I even tried the var (enemyid) = instance_nearest( x , y , obj_enemy ) in the hit object's create event so that it would grab the nearest enemy instances ID and then I stored that in a permanent variable called EID (enemyid = EID) but that doesn't work either.
Surely there must be some way for an instance to check the id number of whatever other instance created it at the point of creating and then store that?
I know you can store the id of whatever instance is being created by the creating instance, using instance_create (there's a tongue twister) but what about the other way around?
Anyway any help would be great. I'm using GM:S 1.4, Win 7, and the code I'm trying to get to work is below.
In STEP event -
Code:
var (whocalled) = instance_position(x,y,obj_enemy)
// Follow Enemy in air
x = whocalled.x;
y = whocalled.y;
z = whocalled.z;
zspeed = whocalled.zspeed;