Edited by _257502, 27 July 2012 - 04:20 PM.
Connect a spawn with an enemy by object ID?
Started by _257502, May 25 2012 08:32 PM
6 replies to this topic
#1
Posted 25 May 2012 - 08:32 PM
Ok, working on my megaman game and I want to create a spawn for the enemies. I want to make it so right before it comes into view it will make an enemy unless it had already made one and it's still alive. For example megaman runs by and triggers a spawn but runs away when the enemy follows and passes the spawn again, the second time it wouldn't trigger because the enemy is still alive. I will be using a couple of these so there will be a couple of the same enemy flying around at the same time. I guess what I want to know is can I attach the spawn to its own enemy by object ID and if so how do I attach it to just that enemy?
#2
Posted 25 May 2012 - 08:37 PM
enemy=instance_create(x,y,obj_enemy);
#3
Posted 25 May 2012 - 08:41 PM
it's like this:
then you can use it for future coding:
create=instance_create(x,y,obj_enemy); //this saves the spawn's id with the variable 'create'
then you can use it for future coding:
if object_exists(spawn)
{//do something}
#4
Posted 26 May 2012 - 03:20 AM
ok, I got all that but how would you set the spawn to only create an enemy if that specific enemy was killed?
Like i want to create an enemy and store its instance_id as a variable, then if the enemy is destroyed it would create a new one it the enemy destroyed had the correct instance_id.
Like i want to create an enemy and store its instance_id as a variable, then if the enemy is destroyed it would create a new one it the enemy destroyed had the correct instance_id.
Edited by _257502, 26 May 2012 - 03:35 AM.
#5
Posted 26 May 2012 - 03:35 AM
It's not the most efficient way, but in the destroy event of the enemy you could put something like:
with (obj_spawner) {
if (enemy == other.id) {
// respawn the enemy, enemy = instance_create(...
// EDIT: or, if you don't want to create it on previous enemy death, you could just set a variable here that allows the spawner to spawn a new enemy when the player is in range
}
}
with (obj_spawner) {
if (enemy == other.id) {
// respawn the enemy, enemy = instance_create(...
// EDIT: or, if you don't want to create it on previous enemy death, you could just set a variable here that allows the spawner to spawn a new enemy when the player is in range
}
}
Edited by Jake Armstrong, 26 May 2012 - 03:36 AM.
#6
Posted 26 May 2012 - 04:29 AM
yeah i think doing it on the object destroy is the right path to go down, i'm doing this in addition to an in range script I just knew how to do the range part already. I'm pretty good with gml, but this issue just seems a bit out of my league.
I tried the object destroy check
and in the telly_maker step i put a check for if alive=0 create it and define myid
but i keep getting an error for the destroy event, after i destroy the 1st telly that it cant identify the myid variable (which makes sense because if the object no longer exists the instance id is non existant also)
I tried the object destroy check
if (self.instance_id=telly_maker.myid) //which I have already defined as the instance id
{telly_maker.alive=0}
and in the telly_maker step i put a check for if alive=0 create it and define myid
but i keep getting an error for the destroy event, after i destroy the 1st telly that it cant identify the myid variable (which makes sense because if the object no longer exists the instance id is non existant also)
#7
Posted 26 May 2012 - 04:44 AM
I'm not entirely sure what you are doing from that little snippet.
I'll try to better explain what I wrote to see if that helps:
with (obj_spawner) { // this runs once for every single spawning object you have. Everything inside the brackets is treated as if it is a script inside that spawning object.
if (enemy == other.id) { // when using a with statement, other.VARIABLE lets you access the variable from the code that is outside the with. We are basically asking if spawner.enemy is equal to the enemy that is being destroyed
// this will only be true for the spawner that created the enemy that just died. Any variables set in this statement will be set for only that spawner that created the enemy that just died.
// Even though this is in the enemy object, the with statement makes it so the variables being set are in the spawner, not the enemy that is about to die so setting a variable for him would be worthless.
alive = 0;
}
}
// Now your spawner can be set to only create a new enemy if alive is equal to 0 (and set alive to 1 when it is created).
I'll try to better explain what I wrote to see if that helps:
with (obj_spawner) { // this runs once for every single spawning object you have. Everything inside the brackets is treated as if it is a script inside that spawning object.
if (enemy == other.id) { // when using a with statement, other.VARIABLE lets you access the variable from the code that is outside the with. We are basically asking if spawner.enemy is equal to the enemy that is being destroyed
// this will only be true for the spawner that created the enemy that just died. Any variables set in this statement will be set for only that spawner that created the enemy that just died.
// Even though this is in the enemy object, the with statement makes it so the variables being set are in the spawner, not the enemy that is about to die so setting a variable for him would be worthless.
alive = 0;
}
}
// Now your spawner can be set to only create a new enemy if alive is equal to 0 (and set alive to 1 when it is created).
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











