Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Clone for clone
- ADAMTHEGREAT2013
- Scratcher
18 posts
Clone for clone
I am making a shooter game where you have to shoot the enemy ships, and I need to make the enemy ships shoot lazers and the best thing i could think of was a clone block. so I added the ‘create clone of’ block but it wont shoot from the cloned spaceships (the spaceships are clones of a hidden spaceship on the screen) even though I am using the ‘When I start as a clone’ block to start the script! Can someone help please?
- Ranger_07
- Scratcher
100+ posts
Clone for clone
One option is to use a list to make the bullet clones. Implementing it would go something like this:
replace the “create clone of” block with this:
replace the “create clone of” block with this:
//the list "laserSpawn" must be for all spritesThen in the laser sprite add this:
add [someLaserType] to [laserSpawn v] //your laser type would be used to create different kinds of lasers
add (x position) to [laserSpawn v]
add (y position) to [laserSpawn v]
add (direction) to [laserSpawn v]
foreverhopefully this helps
create lasers
end
define create lasers
//Make sure you check the "run without screen refresh"
if <(length of [laserSpawn v]) > (0)> then
repeat until <(length of [laserSpawn v]) < (4)>
set [laserType v] to (item (1) of [laserSpawn v]) //the variable "laserType" should be for this sprite only so that each clone can have it as different values
set x to (item (2) of [laserSpawn v])
set y to (item (3) of [laserSpawn v])
point in direction (item (4) of [laserSpawn v])
create clone of [myself v]
repeat (4)
delete (1) of [laserSpawn v]
end
end
end
- NotTheChosen_Coder
- Scratcher
82 posts
Clone for clone
You can put the delete thing on the clone instead without the repeat, unless you make a block and do no screen refresh. One option is to use a list to make the bullet clones. Implementing it would go something like this:
replace the “create clone of” block with this://the list "laserSpawn" must be for all spritesThen in the laser sprite add this:
add [someLaserType] to [laserSpawn v] //your laser type would be used to create different kinds of lasers
add (x position) to [laserSpawn v]
add (y position) to [laserSpawn v]
add (direction) to [laserSpawn v]foreverhopefully this helps
create lasers
end
define create lasers
//Make sure you check the "run without screen refresh"
if <(length of [laserSpawn v]) > (0)> then
repeat until <(length of [laserSpawn v]) < (4)>
set [laserType v] to (item (1) of [laserSpawn v]) //the variable "laserType" should be for this sprite only so that each clone can have it as different values
set x to (item (2) of [laserSpawn v])
set y to (item (3) of [laserSpawn v])
point in direction (item (4) of [laserSpawn v])
create clone of [myself v]
repeat (4)
delete (1) of [laserSpawn v]
end
end
end
Hello, I'm not the chosen coder. Yes I am bad at coding, but it doesn't mean I can't get better!
- Ranger_07
- Scratcher
100+ posts
Clone for clone
If you share the project I could have a look and see if I can get it to work? that did not work
- kiaanmsaha15
- Scratcher
36 posts
Clone for clone
I know for the shooting mechanic!
Bullet:
when green flag clicked
forever
change [cooldown v] by (1)
if <(cooldown) < [6]> then
create clone of [bullet v]
end
end
Bullet:
when green flag clicked
hide
when I start as a clone
repeat until <<touching [enemy v] ?> or <touching [edge v] ?>>
move (7) steps
end
delete this clone
when kiaanmsaha15 clicked
follow kiaanmsaha15
stop [you from unfollowing v]
Hey, I'm @kiaanmsaha15
- Discussion Forums
- » Help with Scripts
- » Clone for clone