Bullets not firing at all (SOLVED)

Discussion in 'Programming' started by joweechao, Dec 4, 2018.

  1. joweechao

    joweechao Member

    Joined:
    Dec 4, 2018
    Posts:
    4
    I'm trying to have some code that fires bullets from the player when the X button is pressed. The code had worked originally, however for some reason it does nothing now. Is there something I accidently changed, please help.

    key_shoot = keyboard_check(ord("X"));

    firingdelay = firingdelay - 1;
    if (key_shoot) && (firingdelay < 0)
    {
    firingdelay = 5;
    with (instance_create_layer(x,other.y,"ArcBullets",arcbulletA))
    {
    speed = 10;
    if (other.image_xscale > 0)
    {
    direction = 0;
    }
    if (other.image_xscale < 0)
    {
    direction = 180;
    }
    }
    }
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,342
    Remember to use code tags, it makes the code easier to read. The basic code looks correct with one possible exception. You have other.y in the instance_create_layer function and while this could be correct, I doubt its what you want. You don't use it for x and more importantly, you don't have anything in your code that implies other would work here (while you need to use other inside of a with statement, stuff in side of the with (here) should not use it for that with statement). Still, I think that would cause a crash unless there actually is an other, in which case maybe the bullet it just spawning in the wrong place?

    If changing that doesn't fix anything, I would recommend the debugger. Place a line break on the with (instance_create_layer... line and step through it to see if and where the bullet is being created.
     
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,647
    Check your bullet code. Make sure it's not destroying itself as soon as it is created. Maybe you have it set to destroy itself upon collision with the player.
     
  4. joweechao

    joweechao Member

    Joined:
    Dec 4, 2018
    Posts:
    4
    The other was a mistake from a attempt I tried to fix the issue, removing that doesn't seem to have any effect at all though. I have the bullet to destroy itself when colliding with walls, but even when I remove that from the bullet code it doesn't even spawn. I tried to set the bullet to spawn somewhere visible on the room but still nothing. I have no idea why it's broken, it worked before but for some reason it just does nothing.
     
  5. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,647
    After you set firingdelay to 5, have it show a message, it can say anything you want, and then test if the message shows up. If the message doesn't show up, then your condition is never even met.

    If the message does show up, then check to make sure the bullet is not a child of any parent object. Then search allscripts, using the menu option, for any other cases of instance destroy that might be pointing to the bullet.
     
  6. TinyGamesLab

    TinyGamesLab Member

    Joined:
    Jun 21, 2018
    Posts:
    77
    Like @TheouAegis said, use a show_message(str); line after the firing delay = 5; line.
    This ways you'll know this condition has been reached.
    If so, place a new show_message(str); inside the with statement to check if the instance was created.
    This way you can check where the code breaks down, which makes it easier to check other parts of your game to fix it.
     
  7. joweechao

    joweechao Member

    Joined:
    Dec 4, 2018
    Posts:
    4
    The message appears when the message code is both after the firingdelay line and in the when statement, yet bullets still refuse to spawn, I have no idea what's going on, is there maybe a better way to write code for a bullet to fire from the player when a button is pressed?
     
  8. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    5,647
    Okay, new test now. Go into the bullet object. Give it a destroy event. Put a show_message() in there. The two messages you got before tell you that the bullet is being created. The with message would not even run if the bullet was ever created. Now you need to see if the bullet is being destroyed right away. If it is, you need to figure out why it is getting destroyed immediately after it gets created. If you do not get a message popping up, that means the bull is not getting destroyed and is thus not getting rendered. if it is not getting rendered, then it is either on a layer that is covered up completely, at a depth that is covered up completely, is set to be not visible, or it has code in the draw event and no draw_self().
     
  9. joweechao

    joweechao Member

    Joined:
    Dec 4, 2018
    Posts:
    4
    Oh my god, I'm such an idiot. As it turns out the code was right from the start, the message was appearing when the bullet was destroyed upon hitting the wall as in its script, yet it was still invisible. Somehow, I had managed to make the object not visible anymore, and it was easy as hitting the checkmark again. I'm so sorry for overlooking this and if I wasted all of your times. Thanks for your help though, the problem has been fixed, sorry again.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice