Legacy GM Debug This Logic Error

P

Pepasone

Guest
I can't seem to figure out what I have wrong.

When I click on the cabbage, it behaves correctly, increases speed, adds score, moves and changes direction. If I click on a powerup, it just uses the code from the bottom as if I clicked on nothing.

So it checks to see if I clicked. I have, then it checks to see if I was over the cabbage or a powerup and I am. If I am over the cabbage, it works correctly. However if I am over a powerup, it skips to the bottom of the code and resets the speed to 4 and multiplier to one.

I appreciate the help!

Code:
if mouse_check_button_pressed(mb_left)
{
    if position_meeting(mouse_x, mouse_y, obj_cabbage) || position_meeting(mouse_x, mouse_y, obj_powerup)
        {
            // THIS IS WHAT HAPPEN WHEN IT IS A CABBAGE
            if position_meeting(mouse_x, mouse_y, obj_cabbage)
            {
                score_current += (score_multiplier * score_base);
                score_multiplier += 1;
          
                // Check if ball_speed is is past 10 keep at ten.
                if ball_speed >= 10
                {
                    ball_speed = 10;
                }

                else
                {
                    ball_speed += 1;
                }
          
                move_random(1, 1);
                motion_set(irandom(359), ball_speed);
            }
           
            // THIS IS WHAT SHOULD HAPPEN IF IT IS A POWERUP
            else
            {
                move_random(1, 1);
                motion_set(irandom(359), ball_speed);
            }
        }

    //THIS IS WHAT IS SUPPOSED TO HAPPEN IF WE CLICK IN THE GAME AREA BUT MISS THE POWERUP AND CABBAGE
    else
        {
            score_multiplier = 1;
            ball_speed = 4;
            move_random(1, 1);
            motion_set(irandom(359), ball_speed);
        }
}
 
Last edited by a moderator:
L

Lars Karlsson

Guest
I tried the code below, it's basically the same but with less stuff. And it's working as intended. So not sure what's going on with yours.
Could you try this version and see what happens?

Code:
if mouse_check_button_pressed(mb_left)
{
    if position_meeting(mouse_x, mouse_y, obj_cabbage) || position_meeting(mouse_x, mouse_y, obj_powerup)
    {
        if position_meeting(mouse_x, mouse_y, obj_cabbage)
        {
            show_message("Hit Cabbage");
        }
        else
        {
            show_message("Hit Powerup");
        }
    }
    else
    {
         show_message("Hit Nothing!");
    }
}
 
P

Pepasone

Guest
I tried the code below, it's basically the same but with less stuff. And it's working as intended. So not sure what's going on with yours.
Could you try this version and see what happens?

Code:
if mouse_check_button_pressed(mb_left)
{
    if position_meeting(mouse_x, mouse_y, obj_cabbage) || position_meeting(mouse_x, mouse_y, obj_powerup)
    {
        if position_meeting(mouse_x, mouse_y, obj_cabbage)
        {
            show_message("Hit Cabbage");
        }
        else
        {
            show_message("Hit Powerup");
        }
    }
    else
    {
         show_message("Hit Nothing!");
    }
}

Hey thanks so much! I didn't know about "show_message" very useful. I did resolve this. I was deleting the powerup once it was clicked, and it was destroying before the above code could check to see if it was hitting it, so when it did get to check, the instance was gone already. Have to delete it afterward! Thanks!
 
Top