Firing delay

Hi could someone tell me how to do two things.

1. Count the number of objects in a scene
2. Add a delay so that when firing, so that to many bullets aren't fired at once.

Comments

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    To answer your first question - Create one game Integer attribute and call it ObjectCount. Keep the value at 0 for the time being.

    In each actor or object add a change attribute near the top :

    Change attribute Game.ObjectCount to Game.Object Count+1
    This will add 1 to the attribute with each actor that is active on the scene.

    Attached is a quick demo I made for you.

    I'm not sure what your asking for your second question - we'd need to know more about your game. How is the actor firing the bullets?
  • DepressedPandaDepressedPanda Member Posts: 215
    edited March 2013
    --------------------
    Add A Delay
    --------------------

    Add a attribute called "can fire" or something like that. It's basically a attribute giving your actor permission to fire. default set it to yes.

    on rule "can fire" == yes {
    fire code here
    set attribute "can fire" off
    timer (after) 1 second { set attribute to "can fire" true }
    }

    That'll stop the ability to fire for one second after every shot.

    -------------------
    Count Objects On Scene
    -------------------

    I guess the easiest way to do that would be to again, set a game attribute for "scene objects" and on every object just add

    change attribute %scene.objects +1

    and then you have your total. If you destroy objects, don't forget to -1 the objects.
  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    edited March 2013
    Or you could just use a timer that says EVERY 1 second spawn an actor. You can wrap this into a boolean rule so it doesn't fire all the time, @DepressedPanda stated. The easier the better. :-)
  • DepressedPandaDepressedPanda Member Posts: 215
    Sure, either way works just as fine. Both will get the job done. :)
  • mhbartabymhbartaby Member Posts: 5
    Great comments and I have it up and working. I am making a space invaders game.

    I used the bullet_count and then ensured that it was less than 1 when you fire the int is changed to 1 when destroyed by leaving room or hitting an alien it resets to 0 allowing fire.

    Counting number of objects was great way I have now figured out attribute. Again thanks.

    I have one more issue should I repost? I will put it to you anyway.

    when my row of aliens reach the game.screen.width-25 I increase the y value and set the alien_speed att to - alien_speed att but it only applies the y to that particular alien and I want to apply it to all. So they all move down, but i can only set self.alien.y
  • mhbartabymhbartaby Member Posts: 5
    edited March 2013
    Removed
  • DepressedPandaDepressedPanda Member Posts: 215
    Are you putting the code in the specific actor or are you editing the prototype of the same actor?

    Putting an action in the Prototype should make every instance of that actor do the action specified.

    If you click the specific actor on your game board it'll only apply to that little fella.
Sign In or Register to comment.