Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Help with scripts
- Deekshan2012t1
-
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:
Enemy bullet:
Please reply if you see this.
Enemy plane:
Enemy bullet:
Please reply if you see this.
- UnconstructivePoster
-
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?
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
-
54 posts
Help with scripts
Sure!
I have added things to some of the code but thats just for extra fx
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
-
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.
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.
- Deekshan2012t1
-
54 posts
Help with scripts
((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.OMG BRO TYSM, I would never have figured this out on my own! It seems like the problem is that
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.
- Deekshan2012t1
-
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?
- Discussion Forums
- » Help with Scripts
-
» Help with scripts