[solved] Instance not creating

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:

Rob

Member
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
 
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).
Yeah. The code for the bat bar is the exact same down to the semicolon.
I'll check the instance_number.
 
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:

TsukaYuriko

šŸŒ 
Forum Staff
Moderator
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?
 
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?
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
 
Top