# I need help programming bullets!

**URL:** https://forum.kirupa.com/t/i-need-help-programming-bullets/264940
**Category:** programming
**Created:** [July 2, 2008, 10:31am UTC](https://forum.kirupa.com/t/i-need-help-programming-bullets/264940 "2008-07-02T10:31:21Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Bolshoi333](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@Bolshoi333](https://forum.kirupa.com/u/Bolshoi333)
#### Post date: [July 2, 2008, 10:31am UTC](https://forum.kirupa.com/t/i-need-help-programming-bullets/264940/1 "2008-07-02T10:31:21Z")

</div>

Below is skeleton code for bullets/various other things that are created in multiples

```auto
var i:Number = 0;
var goTime:Boolean = true;

function newThingy(){
	if(goTime == true){
		attachMovie("thingy", "thingy" +i, i);
		thingy = _root["thingy" +i];
		thingy._x = 100;
		thingy._y = 200;
		goTime = false;
		i++;
	}
	thingy._x += 5;
	if(thingy._x > 550){
		removeMovieClip(this);
	}
}
function timer(){
	goTime = true;
}

setInterval(timer, 500);
this.onEnterFrame = function(){
	newThingy();
}

```

Ok, so whenever I run this code, the “thingy” that was created last stops wherever it is when the next “thingy” is created. How do I make them behave like I want them to, and go all the way to the end of the screen?

---

<div class="post-metadata">

### Author: ![Insane\_au](https://avatars.discourse-cdn.com/v4/letter/i/439d5e/32.png) [@Insane\_au](https://forum.kirupa.com/u/Insane_au)
#### Post date: [July 2, 2008, 11:07am UTC](https://forum.kirupa.com/t/i-need-help-programming-bullets/264940/2 "2008-07-02T11:07:46Z")

</div>

this is AS2 yes?  
Basically what you want to do is have a copy of the bullet off screen which you duplicate to make new bullets.

An example of how to do this: (the attached file)  
I made this _ages_ ago so its not exactly the most clearly written code, PM if you have any further questions.

Hope this helps. 😃

---

<div class="post-metadata">

### Author: ![Bolshoi333](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@Bolshoi333](https://forum.kirupa.com/u/Bolshoi333)
#### Post date: [July 2, 2008, 12:55pm UTC](https://forum.kirupa.com/t/i-need-help-programming-bullets/264940/3 "2008-07-02T12:55:02Z")

</div>

It works beautifully! Thanks a ton 😃

---

<div class="post-metadata">

### Author: ![rrh](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@rrh](https://forum.kirupa.com/u/rrh)
#### Post date: [July 2, 2008, 3:51pm UTC](https://forum.kirupa.com/t/i-need-help-programming-bullets/264940/4 "2008-07-02T15:51:24Z")

</div>

The crucial point isn’t whether you use attachMovie or duplicateMovie. The crucial point is that there is one and only one thingy.  
Consider this:

```auto

function newThingy(){
if(goTime == true){
attachMovie("thingy", "thingy" +i, i);
thingy = _root["thingy" +i];
thingy._x = 100;
thingy._y = 200;
goTime = false;
i++;
thingy.onEnterFrame= function () {
this._x += 5;
if(this._x > 550){
removeMovieClip(this);
}

}
}
}

```

Another solution would be to push thingy to an array, and then every frame, you would loop through the array and move each item in the array.

---

<div class="post-metadata">

### Author: ![Bolshoi333](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@Bolshoi333](https://forum.kirupa.com/u/Bolshoi333)
#### Post date: [July 3, 2008, 1:47am UTC](https://forum.kirupa.com/t/i-need-help-programming-bullets/264940/5 "2008-07-03T01:47:12Z")

</div>

Thanks everyone! The code itself is working fine. Now I just have to figure out why it’s not firing properly ☹
