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

GameMaker [SOLVED] I have problems with sequence and placement of code

sinigrimi

Member
I create a roguelike.
When I enter a new room, the doors are closed, enemies are generated, and when I kill them with oBullet (in the code for colliding oBullet with oEnemy_par it says that if the enemy has hp <= 0 instance_destroy, and then if (! Instance_exist (oEnemy_par)) { the doors open}), the doors open and the enemies creation in this command will be removed from it.

P.S .: If you do not understand what the problem is, then this check only passes if I kill enemies with oBullet.

How can I make the check (! Instance_exist (oEnemy_par)) pass after the generation of enemies and without the participation of oBullet. I just want the enemies to die not only from oBullet but also from many other factors...

I tried to register this check in the player’s step event, but this bypasses the generation of enemies and they are not created.
Or maybe I should write this test in all possible events that can kill enemies? In this case, for each enemy should I remove the check from (if hp <= 0) from the step event?

Now, if I have a collision turned on and oBullet is destroyed in it, then the following code does not work in the enemy step event (because oBullet is destroyed before place_meeting works)
Code:
if(place_meeting(x,y,oBullet))
    {
var nearestBullet
        nearestBullet = instance_nearest(x,y,oBullet);
        direction = point_direction(x,y,nearestBullet.x,nearestBullet.y) +180;
        bounce = true;
            hp -= oBullet.damage - defence;
        alarm[0] = 7;
        with (nearestBullet){
        instance_destroy(); 
        }
    }


Sorry for my english, this is not my native language
 
Last edited:

TheouAegis

Member
Where are you creating the enemies? If you're creating them through code, why not create them in the Room Creation Code (or Settings in older versions) or an instance's Room Start Event? If you're going for a gradual creation effect, rather than them all popping in instantaneously, use an alarm and if the alarm is not counting down, check the number of instances. This would probably be the way to go if you don't technically have rooms and are just clearing and rebuilding one room over and over.

Or you create a state machine for the game overall, creating rooms at one state, populating them at the next state, then checking for instances to open the door in the main state.
 

sinigrimi

Member
Where are you creating the enemies? If you're creating them through code, why not create them in the Room Creation Code (or Settings in older versions) or an instance's Room Start Event? If you're going for a gradual creation effect, rather than them all popping in instantaneously, use an alarm and if the alarm is not counting down, check the number of instances. This would probably be the way to go if you don't technically have rooms and are just clearing and rebuilding one room over and over.

Or you create a state machine for the game overall, creating rooms at one state, populating them at the next state, then checking for instances to open the door in the main state.
I create enemies when the room is created, in the same code immediately after creating the doors and moving the player to the desired point. It’s just that in ds_map / ds_grid / ds_list (I already get confused in them) a mark is put that
this is another room and the scripts are created in it, after that I have to check somewhere oEnemy_par exists to open the room and mark it as “visited” The problem is that if I write it in the step event oplayer they are not created (my oPlayer - persistant because it is also recreated at each transition and its characteristics are not preserved). And I have a check in oBullet, but now I can not do different events with oBullet and oEnemy because place_meetind does not have time to work :(

in script:
Code:
    map[? "visited"] = false; // Initialize whether you have visited the room or not (first set to (false))
...
...
 if map[? "start"] == false
        {
         
                 
        var Lvl1 =choose("BeeRoom", "RatRoom", "SpiderRoom");//,"RandomRoomOne","RandomRoomTwo","RandomRoomThree");
        map[? "enemy"] =Lvl1;
        show_debug_message(string_letters(Lvl1));
...
...

in oController:
Code:
...
case "start":
...
...
    case "enemy": // Создать врагов
         // У нас есть две части информации, хранящейся в «вражеском» ключе карты:
         // тип и номер. Таким образом, мы разделили строку на две части, чтобы получить каждый
         // индивидуальное значение, а затем анализ каждого из них, чтобы создать правильного врага.
     
   var _type = string_letters(map[? "enemy"]);
                switch(_type)
                    {
                    case "BeeRoom":
                         BeeRoom();
                        break;
                    case "RatRoom":
                         RatRoom();
                        break;
                    case "SpiderRoom":
                         SpiderRoom();
                        break;
                     case "RandomRoomOne":
                         instance_create_layer(_xx, _yy, "Instances", oChervyak);
                        break;          
                     case "RandomRoomTwo":
                         instance_create_layer(_xx, _yy, "Instances", oEvilEye);
                        break;
                    case "RandomRoomThree":
                         instance_create_layer(_xx, _yy, "Instances", oPlayer);
                        break;
                    }
        break;
    }
...
...

and in oBullet collision with oEnemy_par:

Code:
/// @description встречи с врагами
with (other)
{
 
if hp <= 0
    {    
    instance_destroy();
    }
}

if !instance_exists(oEnemy_par)
{
var rm = RoomGen_GetRoomNumber(global.RoomGen_x, global.RoomGen_y);
RoomGen_ClearMapEntry(rm, "enemy");
with (obj_RoomGen_DEMO_Door)
    {
    if sprite_index == spr_RoomGen_DoorClosed_H
        {
        sprite_index = spr_RoomGen_DoorOpen_H;
        if image_yscale == 1
            {
            with (instance_position(x - 32, y + 32, obj_RoomGen_DEMO_Wall)) instance_destroy();
            with (instance_position(x + 32, y + 32, obj_RoomGen_DEMO_Wall)) instance_destroy();
            }
        else
            {
            with (instance_position(x - 32, y - 32, obj_RoomGen_DEMO_Wall)) instance_destroy();
            with (instance_position(x + 32, y - 32, obj_RoomGen_DEMO_Wall)) instance_destroy();
            }
        }
    if sprite_index == spr_RoomGen_DoorClosed_V
        {
        sprite_index = spr_RoomGen_DoorOpen_V;
        if image_xscale == 1
            {
            with (instance_position(x + 32, y - 32, obj_RoomGen_DEMO_Wall)) instance_destroy();
            with (instance_position(x + 32, y + 32, obj_RoomGen_DEMO_Wall)) instance_destroy();
            }
        else
            {
            with (instance_position(x - 32, y - 32, obj_RoomGen_DEMO_Wall)) instance_destroy();
            with (instance_position(x - 32, y + 32, obj_RoomGen_DEMO_Wall)) instance_destroy();
            }
        }
    }
}

instance_destroy();
 
Last edited:

TheouAegis

Member
You couldn't do something like
if map[?"start"]==true && !instance_exists(oEnemy_par) {
in the controller object's End Step event and have the door code there?
 

sinigrimi

Member
You couldn't do something like
if map[?"start"]==true && !instance_exists(oEnemy_par) {
in the controller object's End Step event and have the door code there?
Thanks, I used "if! Instance_exists (oEnemy_par) {}" in End Step and it helped. I can’t believe that I’m so stupid, and I forgot that Step events are executed after Create :D events. Thanks again, you're the best!
 
Top