Discuss Scratch

Deekshan2012t1
Scratcher
54 posts

Help with scripts

I'm following a Shoot ‘em up game tutorial however I wanted the enemy planes and the Enemy Bullets to be corresponding colours, however, when 2 enemy planes are on the screen, all the cloned bullets are the same colour. Please help. Here’s my code right now.

Enemy plane:

whenclickedhidesetcounterto0deleteallofXPOSdeleteallofYPOSdeleteallofDIRforeverwait4secsswitchcostumeto(pick random (0) to (2))createcloneofmyself


Enemy bullet:

whenIstartasacloneswitchcostumeto([costume nameofEnemy Plane)]pointindirectionitemCOUNTERofDIRgotox:itemCOUNTERofXPOSy:itemCOUNTERofYPOSrepeatuntilyposition<-179move12stepsdeletethisclone

Please reply if you see this.
UnconstructivePoster
New Scratcher
100+ posts

Help with scripts

Can you share the project and send a link so we can look at more of the code?

I don't immediately see something blatantly wrong with the two scripts you sent, but it depends on whether the other components of the project are working properly. Have you checked that the costume names of the planes and the bullets match up? Also, I assume you have a when I start as a clone script in the plane sprite - what does it look like?
Deekshan2012t1
Scratcher
54 posts

Help with scripts

Sure!
I have added things to some of the code but thats just for extra fx

Last edited by Deekshan2012t1 (July 15, 2023 14:42:02)

UnconstructivePoster
New Scratcher
100+ posts

Help with scripts

It seems like the problem is that ((costume name v) of (enemy plane v)) was detecting the costume of the parent “plane” sprite, not the particular clone producing the bullets. Since the parent plane sprite's costume at any given time is set to the type of plane that was last cloned, this means the bullets' costumes are being set to match the most recently created plane as well. You can see this when, for example, a green plane suddenly starts shooting red bullets the moment a new red plane spawns.

I fixed this by creating a new list to store the bullet costumes instead of using ((costume name v) of (enemy plane v)). You can follow the same format you used for storing x/y position and direction.

whenclicked in the plane sprite. . .deleteallofYPOSdeleteallofCOSTUME add thisforever. . .whenIstartasaclone in the plane sprite. . .forever. . .addypositiontoYPOSaddcostumenametoCOSTUME add thiscreatecloneofEBullet. . .whenIstartasaclone in the EBullet sprite. . .gotox:...y:...switchcostumetoitemCOUNTERofCOSTUME add thisrepeatuntil.... . .
Deekshan2012t1
Scratcher
54 posts

Help with scripts

UnconstructivePoster wrote:

It seems like the problem is that ((costume name v) of (enemy plane v)) was detecting the costume of the parent “plane” sprite, not the particular clone producing the bullets. Since the parent plane sprite's costume at any given time is set to the type of plane that was last cloned, this means the bullets' costumes are being set to match the most recently created plane as well. You can see this when, for example, a green plane suddenly starts shooting red bullets the moment a new red plane spawns.

I fixed this by creating a new list to store the bullet costumes instead of using ((costume name v) of (enemy plane v)). You can follow the same format you used for storing x/y position and direction.

whenclicked in the plane sprite. . .deleteallofYPOSdeleteallofCOSTUME add thisforever. . .whenIstartasaclone in the plane sprite. . .forever. . .addypositiontoYPOSaddcostumenametoCOSTUME add thiscreatecloneofEBullet. . .whenIstartasaclone in the EBullet sprite. . .gotox:...y:...switchcostumetoitemCOUNTERofCOSTUME add thisrepeatuntil.... . .
OMG BRO TYSM, I would never have figured this out on my own!
Deekshan2012t1
Scratcher
54 posts

Help with scripts

Hold on, I've recently gotten these lag spikes (quite often) and sometimes the Enemy Planes (now I call shoortes) sometimes shoot the most recent enemy plane's bullet. Is there a way to prevent this?

Powered by DjangoBB