Firing delay
mhbartaby
Member Posts: 5
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.
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
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?
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
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.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
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
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.