• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 Bat Bar

Hi

I'm having trouble with some of my code. I was hoping that someone could see what I'm doing wrong, I'm at a wall?

Bat2 is an object on the top of the screen. There is a bunch of these Bat2, Bat3, Bat4, etc. objects. They have to be unlocked
to use, that is to drop the bat onto the play field. Inside each block is either a bat face or a greyed out bat face (hasn't been unlocked)

1603142160675.png

The greyed faces are inside the Bat2, Bat3, etc. If you have enough gems you can use your gems to unlock
one of the faces and make a new bat available.

problem:

Left clicking on the greyed faces brings up a dialogue asking if you want to unlock that bat. If you do,
a normal bat face appears, replacing the greyed face. Problem is, the unlocking isn't working. I'm clicking
on them but they don't change, its as if they aren't even there.

So, the Bats2, Bats3, Bats4 are the squares to unlock.

GML:
if (Player.hasbatB == true)
{
    if global.dropped_bat == false
    {
        if (position_meeting(mouse_x, mouse_y, BatsFaceB))
        {
            if (mouse_check_button_released(mb_left) && (global.can_click))
            {
                global.select_bat = 2;      //the bet to drop
                global.lightning_drop = true;
                global.lightning_drop_myTimer = room_speed;
            
                instance_create_depth(270, 9, -15000, DropBatObject);
                audio_play_sound(PickBat, 10, false);
                alarm[0] = 20;
            }
        }
    }
}
There is a bat object call DropBatObject that flying down to the playfield. Its created by the prior code. (DropBatObject)

Code:
//this is a cool down period for picking a bat
global.sentry_myTimer--;
show_debug_message("DropBatObject");

if (y > 800)
{
    show_debug_message("y > 800")
    with (Player)
    {
        //if there is a dropped bat (space for a bat to drop)
        show_debug_message("dropped bat");
        if (global.dropped_bat == false)
        {
            //dracula pointing
            with (DraculaObject)
            {
            
            show_debug_message("Dracula should be DraculaPointing")
                sprite_index = DraculaPointing
                image_speed = 0
                image_index = 2
                
    
            }
            with (SnowDrac)
            {
                sprite_index = SnowDracSendOutBats
                image_speed = 0.01
                global.dracula_drop_myTimer = room_speed;
            }
            global.dracula_myTimer = 0;
        
            
            if (global.select_bat == 2)
            {
                show_debug_message("Creating instance of lightning bat");
                global.current_bat = instance_create_depth(390, 1050, -1500, LightningBatObject);
                num_lit = instance_number(global.current_bat);
                show_debug_message("Number of lightning: " + string(num_lit))
                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;
                                    
                            
                        }
                    }   
                    
                }
                
            }
Then there is the actual faces. The locked faces (BatsFaceHiddenB for example), are like this:

Code:
draw_self()





/// @description Insert description here
// You can write your code in this editor

draw_text_ext_transformed_color(400, 300, "Do you wish to unleash this bat?", 30, 100, 5, 5, 0, c_red, c_red, c_red, c_red, 1)
draw_text_ext_transformed_color(400, 400, "Yes??", 30, 100, 5, 5, 0, c_red, c_red, c_red, c_red, 1)
draw_text_ext_transformed_color(400, 500, "No!", 30, 100, 5, 5, 0, c_red, c_red, c_red, c_red, 1)


//ALL THIS IS THE CASE OF UNLOCKING THE BATS

if mouse_check_button_released(mb_left)
{
    show_debug_message("button check clear")
    //if (mouse_x > 400 && mouse_x < 800)
    //{
        show_debug_message("x coordinates clear")
        //if (mouse_y > 300 && mouse_y <= 600)
        //{
            show_debug_message("y coordinates clear")
            
    
            
    
    
        //
        //
            inst = instance_create_depth(300,400, -1000, BatsFaceB)
            Player.hasbatB = true
            show_debug_message("Creating Bats Face B")
            BatsFaceB.visible = true
            instance_destroy()
                //with (BatsFaceHiddenB)
                //{
                //    visible = false;
                //}
            //}

}

        

//No
if mouse_check_button_released(mb_left)
{
    if (mouse_x > 400 && mouse_x < 800)
    {
        if (mouse_y > 600 && mouse_y <= 800)
        {

            with (Player)
            {
                hasbatB = true
    
                instance_create_depth(300,40, -2100, BatsFaceB)
                //draw_sprite(LightningBatFace, 0, x, y-10);
            }

        }
    }
}
So in general, it works like this. the player clicks on the squares (the Bats2, Bats3, etc.). If it is greyed out that means it needs to be unlocked. So I click on the second box (with the greyed out face) and it prompts you asking if you want to buy this bat. If you do the block face becomes a bat face (not greyed out) From then on you can click on the bat face in the box and the DropBatObject flies down from the Bat Bar where the Boxes are and drops the lightning bat. (if you click on the second bat face it drops that type of bat.) I know this is quite complication but I'm at a standstill on what to do or test it.
I guess I'm just asking for second pair of eyes.

What it is doing now is just this: i click on the greyed out faces and nothing happens. But at one point while I was coding this I did have it working right. It changed the bat faces, and dropped the bat.
 
I think it's because your if-statement in ln34...
GML:
if (global.select_bat == 2)
The DropBat(?) script is only set to execute on that condition. Your selection value is only set to 2 and doesn't change. Therefore it only selects Bat2. What you would need to do is construct an event where the global.select_bat value can be controlled. Then set it to where each number can be handled as you want it when the player hasbat. In whichever object is the controller, I'd personally recommend using a case/switch method at that point. I am assuming the full list of bats will not be too excessive so I can suggest something like this.

Code:
switch(global.select_bat)
{
case 2:
//Your Bat2 script here
break;

case 3:
//Your Bat3 script here
break;

case 4:
//Your Bat4 script here
break;
}
Also, I am really not sure why debug messages are being used instead of draw_text(x, y, "Your message");
I personally wouldn't advise using debug messages for ANYTHING, but you don't have to take my word for it. ;)
 

TailBit

Member
As the code is now, all the BatsFaceHidden* should be drawing the "Do you wish to unleash this bat?" message on top of each other from when you start the room, and on LMB release you should at least be seeing
show_debug_message("button check clear") message in the console.. not nothing ..

But BatsFaceHiddenB looks like a question dialogue object you would create after pressing a button?
 
@Dogwithswords Well that isn't the complete code. I truncated it. The complete event is:

//this is a cool down period for picking a bat
global.sentry_myTimer--;
show_debug_message("DropBatObject");

if (y > 800)
{
show_debug_message("y > 800")
with (Player)
{
//if there is a dropped bat (space for a bat to drop)
show_debug_message("dropped bat");
if (global.dropped_bat == false)
{
//dracula pointing
with (DraculaObject)
{

show_debug_message("Dracula should be DraculaPointing")
sprite_index = DraculaPointing
image_speed = 0
image_index = 2


}
with (SnowDrac)
{
sprite_index = SnowDracSendOutBats
image_speed = 0.01
global.dracula_drop_myTimer = room_speed;
}
global.dracula_myTimer = 0;

if (global.select_bat == 1)
{
show_debug_message("select bat is 1")
//if the slot A is available to pull down
if (hasbatA)
{
//if (global.can_click && global.sentry_myTimer <= 0) {

//global.current_bat = instance_create_depth(340, 950, 1700, SentryBatObject);
//create a bat and set it tot he global.current_bat
global.current_bat = instance_create_depth(340, 950, -1500, SentryBatObject);
//sprite_index = DraculaStatic
//sprite_index = DraculaStatic
num_sent = instance_number(global.current_bat);
show_debug_message("Sentry Bats #:" + string(num_sent));
audio_play_sound(SentryBat, 10, false);
//set a dropped bat to true - the drop spot is occupieed
global.dropped_bat = true;
//reset the cool down period for picking a bat
global.sentry_myTimer = room_speed;
with (EightStarObject)
{
image_index = 1;
global.hex_myTimer = room_speed;
}
// }
show_debug_message("Sentry Bat coords:x " + string(global.current_bat.x) + " :y:" + string(global.current_bat.y))

}
}

if (global.select_bat == 2)
{
show_debug_message("Creating instance of lightning bat");
global.current_bat = instance_create_depth(390, 1050, -1500, LightningBatObject);
num_lit = instance_number(global.current_bat);
show_debug_message("Number of lightning: " + string(num_lit))
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;


}
}

}

}
if (global.select_bat == 3)
{
global.current_bat = instance_create_depth(340, 980, -1500, WindBatObject);

with (global.current_bat)
{
audio_play_sound(DropWindBat, 10, false);
sprite_index = WindBatStill;
global.dropped_bat = true;
audio_play_sound(HurricaneBat, 10, false);
if (!global.is_anarchyMode)
{
Player.hasbatC = false;
Player.myTimerbatC = true;
global.chourglass = instance_create_depth(Bats3.x, Bats3.y, 1700, myTimerHourglassObject);
global.batCmyTimer = 0;
global.batCcountdodwn = room_speed*50;

}
else
{
Player.hasbatC = true;
Player.myTimerbatC = false;
//global.chourglass = instance_create_depth(Bats3.x, Bats3.y, -10000, myTimerHourglassObject);
//global.batCmyTimer = 0;
//global.batCcountdodwn = room_speed*50;
}
}

}
if (global.select_bat == 4)
{
global.current_bat = instance_create_depth(330, 950, -1500, PoisonBatObject);

with (global.current_bat)
{
sprite_index = PoisonBatStatic;
global.dropped_bat = true;
audio_play_sound(AcidBat, 10, false);
if (!global.is_anarchyMode)
{
Player.hasbatD = false;
Player.myTimerbatD = true;
Player.dhourglass = instance_create_depth(Bats4.x+50, Bats4.y, 1700, myTimerHourglassObject);
Player.batDmyTimer = 0;
Player.batDcountdown = room_speed*50;
}
else
{
Player.hasbatD = true;

Player.myTimerbatD = false;


}
}
}
if (global.select_bat == 5)
{

global.current_bat = instance_create_depth(320, 950, -1500, SnowBatObject);
with (global.current_bat)
{
sprite_index = SnowFrozenEnemy;
global.dropped_bat = true;
audio_play_sound(DropSnowBat, 10, false);
audio_play_sound(FreezeBat, 10, false);
if (!global.is_anarchyMode)
{
Player.hasbatE = false;
Player.myTimerbatE = true;
global.ehourglass = instance_create_depth(Bats5.x, Bats5.y, 1700, myTimerHourglassObject);
global.batEmyTimer = 0;
global.batEcountdodwn = room_speed*50;
}
else
{
Player.hasbatE = true;
Player.myTimerbatE = false;
}


}
}
if (global.select_bat == 6)
{
global.current_bat = instance_create_depth(320, 400, -1500, MuscleBatObject);
global.dracula_myTimer = room_speed*5;

with (global.current_bat)
{
sprite_index = MuscleBatRunAttack;
audio_play_sound(MuscleBat, 10, false);
/*
sprite_index = MuscleBatStaticBreathing;
global.dropped_bat = true;

if (!global.is_anarchyMode)
{
Player.hasbatF = false;
Player.myTimerbatF = true;
global.batFmyTimer = 0;
global.batFcountdodwn = room_speed*50;
global.fhourglass = instance_create_depth(Bats6.x, Bats6.y, -10000, myTimerHourglassObject);
}
else
{
Player.hasbatF = true;
Player.myTimerbatF = false;

}
*/

}
}

if (global.select_bat == 7)
{
global.current_bat = instance_create_depth(320, 950, -1500, BombBatObject);

with (global.current_bat)
{
sprite_index = BombBat;
global.dropped_bat = true;
audio_play_sound(ExplosiveBat, 10, false);
if (!global.is_anarchyMode)
{
Player.hasbatG = false;
Player.myTimerbatG = true;
Player.is_bomb_bat = true;
global.ghourglass = instance_create_depth(Bats7.x, Bats7.y, 1700, myTimerHourglassObject);
global.batGmyTimer = 0;
global.batGcountdodwn = room_speed*50;
}
else
{
Player.hasbatG = true;
Player.myTimerbatG = false;
Player.is_bomb_bat = true;

}
}
}
if (global.select_bat == 8)
{

global.current_bat = instance_create_depth(320, 950, -1500, MagicBatObject);
with (global.current_bat)
{
sprite_index = MagicBatStatic;
global.dropped_bat = true;
audio_play_sound(MagicBat, 10, false);
audio_play_sound(MagicBatDrop, 10, false);
if (!global.is_anarchyMode)
{
Player.hasbatH = false;
Player.myTimerbatH = true;
global.hhourglass = instance_create_depth(Bats5.x, Bats5.y, 1700, myTimerHourglassObject);
global.batHmyTimer = 0;
global.batHcountdodwn = room_speed*50;
}
else
{
Player.hasbatH = true;
Player.myTimerbatH = false;
}

}

}

}

}
instance_destroy();

}
 
Top