This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-07-03 19:47:38

HunterE30633
Scratcher
Registered: 2007-07-02
Posts: 3

help me with duplicating

so i want to shoot something repeatedly. i tried doing a broadcast and go to function so that the bullet would go to the person then shoot in the direction he is shooting. problem is when i try shooting fast, the bullet that is flying is deleted to make room for the new one that is shot. does anyone know how to make it so that i can shoot something alot without interfering with something else?

Offline

 

#2 2007-07-03 21:19:26

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: help me with duplicating

Well your bullet sprites are not really being deleted. It is just whenever you shoot the bullet sprite goes back to the player and it may not have had enough time to hit its target. Try to make it so it can't be shot when it is moving towards a target.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#3 2007-07-04 00:31:29

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: help me with duplicating

The only way to have multiple shots on screen is by creating multiple bullet sprites, and you need a means of control to make checks to see which bullets are available and only fires one of them.

Each bullet would likely need a global variable e.g. firing1, firing2...  which is zero by default but is set to 1 whilst the bullet is in motion.

Each bulletcwould have a "When I Recieve" block at the start of its firing routine.

Then on your firebutton you check each bullet sequentially, and broadcast the appropriate firing message as soon as you find a bullet that isn't firing.

Then your firing script


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#4 2007-07-04 04:06:33

bigB
Scratcher
Registered: 2007-06-09
Posts: 100+

Re: help me with duplicating

similar to mayhems idea i think you could have one variable called whichbullet. 
the first bullet has a script like this.
when key space pressed: if whichbullet=1 carry out fire routine set which bullet to 2

each bullet has a similar script but the last one sets the variable back to 1.


http://scratch.mit.edu/projects/bigB/260981 Draw to Text
http://scratch.mit.edu/projects/bigB/181829 3D Stunt Flyer

Offline

 

#5 2007-07-04 12:07:43

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: help me with duplicating

You can make the scripts more similar by using
   whichbullet =  (whichbullet +1) mod num_bullets
in each sprite, giving values from 0 to num_bullets-1

The only difference between sprites is what number they compare whichbullet to.
I used this in my polyphonic piano:
http://scratch.mit.edu/projects/kevin_karplus/2160
to have 4 arrows

Offline

 

#6 2007-07-04 12:51:16

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: help me with duplicating

bigB wrote:

similar to mayhems idea i think you could have one variable called whichbullet. 
the first bullet has a script like this.
when key space pressed: if whichbullet=1 carry out fire routine set which bullet to 2

each bullet has a similar script but the last one sets the variable back to 1.

The difficulty here is that if the 1st bullet has hit an enemy and is therefore theoretically available, but 2 is still in flight, you can either not fire 1, or if it has reset to "bullet 1" you can fire 1, set whichbullet to 2, only to find that bullet 2 hasn't hit anything yet and so isn't available.

Hence my preference for checking for the availability of individual bullets, sequentially.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#7 2007-07-04 17:51:34

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: help me with duplicating

I think bigB's idea was to have enough bullets that the first one would have gone off screen, timed-out, or in some other way become available before it is requested again.
This is simpler than having each bullet keep track of its availability, but does require having enough bullet sprites.

Offline

 

Board footer