1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

[solved] Instance not creating

Discussion in 'Programming' started by Twilight Raven, Feb 14, 2020 at 4:14 AM.

  1. Twilight Raven

    Twilight Raven Member

    Joined:
    Sep 1, 2016
    Posts:
    835
    Hi.

    I have a bar at the top of my game where you can select a bat to use in the game to fight the enemy.
    I want to, for example, use a lightning bat. So I click on the lightning bat icon and it should (in every other level does) instantiate a lightning bat. I don't know what seperates this level from the others. I ran it through the debugger and threw in some debugging statements and for all logic it should create the bat.

    This is the code to create the lightning bat:
    if (global.select_bat == 2)
    {
    show_debug_message("Creating instance of lightning bat");
    global.current_bat = instance_create_depth(390, 1050, -2100, LightningBatObject);
    with (global.current_bat)
    {
    show_debug_message("global.current_bat");
    audio_play_sound(LightningStrike, 10, false);
    if (Player.hasbatB)
    {

    show_debug_message("Player hasBatB");
    sprite_index = LightningBatStill;
    global.dropped_bat = true;
    audio_play_sound(LightningBat, 10, false);
    if (!global.is_anarchyMode)
    {
    Player.hasbatB = false;
    Player.myTimerbatB = true;
    show_debug_message("Player has myTimerBatB + " + string( Player.myTimerbatB));
    show_debug_message("PLayer has hasbatB: " + string(Player.hasbatB));

    global.bhourglass = instance_create_depth(Bats2.x, Bats2.y, -1100, myTimerHourglassObject);
    global.batBmyTimer = 0;
    global.batBcountdodwn = room_speed*50;
    }

    else
    {
    Player.hasbatB = true;
    Player.myTimerbatB = false;
    show_debug_message("Player has myTimerBatB + " + string( Player.myTimerbatB));
    show_debug_message("PLayer has hasbatB: " + string(Player.hasbatB));

    //global.bhourglass = instance_create_depth(Bats2.x, Bats2.y, -10000, myTimerHourglassObject);
    //global.batBmyTimer = 0;
    //global.batBcountdodwn = room_speed*50;


    }
    }

    }

    }
     
    Last edited: Feb 14, 2020 at 4:55 AM
  2. Rob

    Rob Member

    Joined:
    Jul 12, 2016
    Posts:
    766
    Have you double/triple checked the x/y/depth that you use in instance_create_depth? is the room you're talking about a different size (eg could the bat be off the visible screen).

    You can use instance_number(LightningBatObject) to see how many instances of an object exist
     
  3. Twilight Raven

    Twilight Raven Member

    Joined:
    Sep 1, 2016
    Posts:
    835
    Yeah. The code for the bat bar is the exact same down to the semicolon.
    I'll check the instance_number.
     
  4. Twilight Raven

    Twilight Raven Member

    Joined:
    Sep 1, 2016
    Posts:
    835
    I did instance_number and got back 1 ike its supposed. SO for some reason this lightning bat isn't being drawn. The code for picking a bat is shared between levels. So, in theory, it should work on one level the same as on another.. That however, isn't the case
     
    Last edited: Feb 14, 2020 at 5:29 AM
  5. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,948
    Check the position of the instance in question. Maybe it's being created off-screen?
    Also check whether you have anything that's covering it up (like a background or other massive sprite being drawn at low depth), or if it's visible (does anything ever make it turn invisible?). Are you changing its image_alpha anywhere or drawing it at anything aside from full alpha?
     
  6. Twilight Raven

    Twilight Raven Member

    Joined:
    Sep 1, 2016
    Posts:
    835
    So I created a new room copied all the objects into it and it started working again. Well sort of. There is 8 bats. The first is the sentry bat. I had two problems. Some levels had alll of the bats not working, other levels it was just the sentry bat not dropping. So I created the new rooom and it fixed the case w here all of them don't work. However, I haven't fixed the senry bat issue.

    So for the sentry bat I checked to see if its being created off screen and its not. The coordinate sare 300x, 900y. How would it be created off screen? So I stripped the level down to one item and added them back one by one and
    found that it was the Snow Frenkentein that was causing the problem.

    Turns on I had some copied code that was doing a with () instance_destroy on the creation of the object
     
  7. Twilight Raven

    Twilight Raven Member

    Joined:
    Sep 1, 2016
    Posts:
    835

Share This Page