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

Windows change room dead intruders

tatko

Member
Hi ,
I don't know how to secure if I shoot all the intruders,
I change the room, I return, the invaders come back to life.
When I click the persistent, the invaders remain dead,
but the living ones follow me to the second room :))
 

jo-thijs

Member
Hi ,
I don't know how to secure if I shoot all the intruders,
I change the room, I return, the invaders come back to life.
When I click the persistent, the invaders remain dead,
but the living ones follow me to the second room :))
GameMaker has object/instance persistence and room persistence.
It sounds like you tried to use object persistence.
I disrecommend using room persistence in general.
In this case, I'd also disrecommend using object persistence, because you should only use object persistence to bring an object along with you to an other room.

Last time I checked, GameMaker assigns constant instance identifiers to instances placed inside the room editor.
You can use this to keep track of which intruders have been shot in some global ds_map and check that in the intruders' create event and make them destroy themselves if they have been shot before.

It could look something like this:
In some initialization room at the start of your game, you execute this in the room creation event:
GML:
// Set of shot intruders: initially empty
global.shot_intruders_set = ds_map_create();
room_goto_next();
In the create event of the intruder objects:
GML:
// Check if intruder has been shot already
if !is_undefined(global.shot_intruders_set[?id]) {
    instance_destroy();
}
In the destroy event of the intruder objects:
GML:
// Mark this intruder as being shot
global.shot_intruders_set[?id] = true;
I hope this helps!
Feel free to ask any questions you have!
 

tatko

Member
perfect !!
but I don't understand anything :))

my code object : o_enemy:

create:

dead = false;
speed = 2;

collision >>o_bullet :
if (!dead)
{
instance_destroy(other);
dead = true;
}

step:
if dead
{
speed=0;
instance_destroy();

}

??? :)
 

woods

Member
//////at the start of your game, you make an empty list?
In some initialization room at the start of your game, you execute this in the room creation event:
GML:
// Set of shot intruders: initially empty
global.shot_intruders_set = ds_map_create();
room_goto_next();



//////if the intruder is on the list already, destroy it as soon as its created?
In the create event of the intruder objects
GML:
// Check if intruder has been shot already
if !is_undefined(global.shot_intruders_set[?id]) {
instance_destroy();
}




//////if the intruder has been shot add it to the list?
In the destroy event of the intruder objects:
GML:
// Mark this intruder as being shot
global.shot_intruders_set[?id] = true;
 

jo-thijs

Member
perfect !!
but I don't understand anything :))

my code object : o_enemy:

create:

dead = false;
speed = 2;

collision >>o_bullet :
if (!dead)
{
instance_destroy(other);
dead = true;
}

step:
if dead
{
speed=0;
instance_destroy();

}

??? :)
Add an empty room at the start of the game and call it rm_init.
In the room creation code of rm_init, put this code:
GML:
// Set of shot intruders: initially empty
global.shot_intruders_set = ds_map_create();
room_goto_next();
This creates a datastructure and puts its identifier in a global variable.
More specifically, the data structure being created, is a map.

Then use as code for o_enemy:
create:
GML:
dead = false;
speed = 2;

// Check if intruder has been shot already
if !is_undefined(global.shot_intruders_set[?id]) {
    dead = true;
}
collision >> o_bullet:
GML:
if !dead {
    instance_destroy(other);
    dead = true;
}
step:
GML:
if dead {
    // Mark this intruder as being shot
    global.shot_intruders_set[?id] = true;
   
    speed=0;
    instance_destroy();
}
Everything I added just checks or inserts values into the map we created in the initalization room.
I'm using accessors to do this consisely.

Let me know if you have further questions!

//////at the start of your game, you make an empty list?
In some initialization room at the start of your game, you execute this in the room creation event:
GML:
// Set of shot intruders: initially empty
global.shot_intruders_set = ds_map_create();
room_goto_next();



//////if the intruder is on the list already, destroy it as soon as its created?
In the create event of the intruder objects
GML:
// Check if intruder has been shot already
if !is_undefined(global.shot_intruders_set[?id]) {
instance_destroy();
}




//////if the intruder has been shot add it to the list?
In the destroy event of the intruder objects:
GML:
// Mark this intruder as being shot
global.shot_intruders_set[?id] = true;
Those are accurate descriptions.
I'm not sure if the question marks indicate them being questions.
 

woods

Member
one of those late night/little sleep comments... mainly seeking verification that i wasnt translating it poorly ;o)
 

tatko

Member
rm_init = must be first !!
Rooms:
1. rm_init
2. Room1
3. Room2
.....to
10 Roomx
victory works :))
thank you :):)
 
Top