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

rookie asks for help part II

Discussion in 'Programming' started by netoxinaa, Apr 29, 2019.

Tags:
  1. netoxinaa

    netoxinaa Member

    Joined:
    Apr 25, 2019
    Posts:
    16
    hey there, i´m working on a space shooter as my first game and i would like to know how to make an enemy shoot every x seconds. i tried to set an alarm in the enemy´s step event but it wont run it.
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,231
    You should post your code as that is helpful (often necessary) to answer the question. But most likely, you are resetting the alarm before it finishes. For example, if you are doing this:

    Code:
    
    ///step event
    alarm[0] = 60;
    
    
    Then every single step the alarm gets set to 60, counts down to 59, and is reset again. There are many solutions to this problem, but the simplest one that uses the built in alarms is this:

    Code:
    
    if (alarm[0] == -1) {
        alarm[0] = 60;
    }
    
    
    This will only set the alarm if the alarm is equal to -1 which is what alarms are in GM when they are off.

    Other options (which might be helpful just in general to understanding how this type of problem is dealt with) are:
     
    netoxinaa likes this.
  3. BattleRifle BR55

    BattleRifle BR55 Member

    Joined:
    Jun 24, 2016
    Posts:
    1,074
    If your AI is really simple, just set the alarm in the Create event and in the Alarm event itself so it cycles infinitely.
     
    netoxinaa likes this.
  4. netoxinaa

    netoxinaa Member

    Joined:
    Apr 25, 2019
    Posts:
    16
    thanks man, i managed to solved it just by moving my alarm setting into the create event, gonna check the info tho
     
    samspade likes this.

Share This Page