Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Help me again
- user432109
-
22 posts
Help me again
Hi, I'm working on a idle tower defence upgrade tycoon type game and I need help
Here's what I have so far: https://scratch.mit.edu/projects/868524426/
1. I need help with the turret shooting the clones after the first one is dead
2. I need help so that the clones also have 5 hit points
3. I need help so that once the clone is dead it doesn't double
4. Everytime the bullet disapears more clones are made
Here's what I have so far: https://scratch.mit.edu/projects/868524426/
1. I need help with the turret shooting the clones after the first one is dead
2. I need help so that the clones also have 5 hit points
3. I need help so that once the clone is dead it doesn't double
4. Everytime the bullet disapears more clones are made
Last edited by user432109 (Feb. 26, 2025 01:23:40)
- imfh
-
1000+ posts
Help me again
It looks like one of your biggest problems is a misunderstanding of how clones and broadcasts work. Remember: Clones can receive broadcasts.
If you have code like this:
You will create a big problem. Every time you broadcast Get Hurt, every clone will clone itself. This will make your sprites start doubling.
To get around this, you can create variables which have “for this sprite only” enabled. These variables are different for every clone you make. Your health variable should be for this sprite only instead of for all sprites.
With a for this sprite only variable, you can do this:
I would fix your code by doing something like this:
I also notice that your bullet clones are sending broadcasts whenever they get deleted to tell the turret to do the firing animation. Similarly, the enemy sprite creates a clone when it gets deleted. This is kind of confusing. Instead, I would a single loop in the original sprites to handle making clones. This will make it easier to eliminate bugs.
I hope this gives you some ideas!
If you have code like this:
You will create a big problem. Every time you broadcast Get Hurt, every clone will clone itself. This will make your sprites start doubling.
To get around this, you can create variables which have “for this sprite only” enabled. These variables are different for every clone you make. Your health variable should be for this sprite only instead of for all sprites.
With a for this sprite only variable, you can do this:
I would fix your code by doing something like this:
I also notice that your bullet clones are sending broadcasts whenever they get deleted to tell the turret to do the firing animation. Similarly, the enemy sprite creates a clone when it gets deleted. This is kind of confusing. Instead, I would a single loop in the original sprites to handle making clones. This will make it easier to eliminate bugs.
I hope this gives you some ideas!
- user432109
-
22 posts
Help me again
So do I delete all my original code and replace it with this?
- user432109
-
22 posts
Help me again
So do I delete all my original code and replace it with this? It looks like one of your biggest problems is a misunderstanding of how clones and broadcasts work. Remember: Clones can receive broadcasts.
If you have code like this:
You will create a big problem. Every time you broadcast Get Hurt, every clone will clone itself. This will make your sprites start doubling.
To get around this, you can create variables which have “for this sprite only” enabled. These variables are different for every clone you make. Your health variable should be for this sprite only instead of for all sprites.
With a for this sprite only variable, you can do this:
I would fix your code by doing something like this:
I also notice that your bullet clones are sending broadcasts whenever they get deleted to tell the turret to do the firing animation. Similarly, the enemy sprite creates a clone when it gets deleted. This is kind of confusing. Instead, I would a single loop in the original sprites to handle making clones. This will make it easier to eliminate bugs.
I hope this gives you some ideas!
- imfh
-
1000+ posts
Help me again
No, don't do that. It probably won't work if you do that. You can update your code based on what I said, but I would not start over using the code I gave you. So do I delete all my original code and replace it with this?
The code I gave is just to highlight what your problem is and some ways you can fix it. It isn't meant to totally replace your code.
- thisisagoodway
-
34 posts
Help me again
Got it, okay, (user432109 is the same person as me, this is my main)No, don't do that. It probably won't work if you do that. You can update your code based on what I said, but I would not start over using the code I gave you. So do I delete all my original code and replace it with this?
The code I gave is just to highlight what your problem is and some ways you can fix it. It isn't meant to totally replace your code.
- user432109
-
22 posts
Help me again
Is the “when I recieve broadcast1” is that supposed to be when I recieve hurt or somthing? It looks like one of your biggest problems is a misunderstanding of how clones and broadcasts work. Remember: Clones can receive broadcasts.
If you have code like this:
You will create a big problem. Every time you broadcast Get Hurt, every clone will clone itself. This will make your sprites start doubling.
To get around this, you can create variables which have “for this sprite only” enabled. These variables are different for every clone you make. Your health variable should be for this sprite only instead of for all sprites.
With a for this sprite only variable, you can do this:
I would fix your code by doing something like this:
I also notice that your bullet clones are sending broadcasts whenever they get deleted to tell the turret to do the firing animation. Similarly, the enemy sprite creates a clone when it gets deleted. This is kind of confusing. Instead, I would a single loop in the original sprites to handle making clones. This will make it easier to eliminate bugs.
I hope this gives you some ideas!
- user432109
-
22 posts
Help me again
Heres what I have from what you gave me: https://scratch.mit.edu/projects/868524426/No, don't do that. It probably won't work if you do that. You can update your code based on what I said, but I would not start over using the code I gave you. So do I delete all my original code and replace it with this?
The code I gave is just to highlight what your problem is and some ways you can fix it. It isn't meant to totally replace your code.
- user432109
-
22 posts
Help me again
Are you there?No, don't do that. It probably won't work if you do that. You can update your code based on what I said, but I would not start over using the code I gave you. So do I delete all my original code and replace it with this?
The code I gave is just to highlight what your problem is and some ways you can fix it. It isn't meant to totally replace your code.
- Discussion Forums
- » Help with Scripts
-
» Help me again