Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Help with Plants VS Zombies scripting.
- MechaDuck
-
10 posts
Help with Plants VS Zombies scripting.
I'm making a game for a school project, and I chose PvZ. It is going well, but I need help with 2 things.
1: How do I make something dragable only once?
2: I have made it so that when a seed packet is click, a clone of the packet's plant is made, but whenever I drag (example) a sunflower, the sun appears by the main one. How can I fix it?
Thank you for helping!
Or don't…
1: How do I make something dragable only once?
2: I have made it so that when a seed packet is click, a clone of the packet's plant is made, but whenever I drag (example) a sunflower, the sun appears by the main one. How can I fix it?
Thank you for helping!
Or don't…

- drmcw
-
1000+ posts
Help with Plants VS Zombies scripting.
1. Use a variable. Assuming you're using clones
2 you need to share the project to work that out
2 you need to share the project to work that out
- Koopakid6000
-
100+ posts
Help with Plants VS Zombies scripting.
For the draggable only once, make it so that the clones stamp themselves then delete the clones, and to make the plants functional make an invisible-costumed sprite that goes to the stamps to make them function. As for the sun appearing by the packet, I would suggest putting the generate sun script under when I start as a clone but it's a little harder to identify the problem since we can't see the project. Please share it and give a link.
- MechaDuck
-
10 posts
Help with Plants VS Zombies scripting.
For the draggable only once, make it so that the clones stamp themselves then delete the clones, and to make the plants functional make an invisible-costumed sprite that goes to the stamps to make them function. As for the sun appearing by the packet, I would suggest putting the generate sun script under when I start as a clone but it's a little harder to identify the problem since we can't see the project. Please share it and give a link.
Can I have a simple explanation. I am using GIFs and clones. Does that help?
Last edited by MechaDuck (April 6, 2016 18:52:06)
- BKFighter
-
1000+ posts
Help with Plants VS Zombies scripting.
I would go the route @drmcw said unless it doesn't need to run code.For the draggable only once, make it so that the clones stamp themselves then delete the clones, and to make the plants functional make an invisible-costumed sprite that goes to the stamps to make them function. As for the sun appearing by the packet, I would suggest putting the generate sun script under when I start as a clone but it's a little harder to identify the problem since we can't see the project. Please share it and give a link.
Can I have a simple explanation. I am using GIFs and clones. Does that help?
- MechaDuck
-
10 posts
Help with Plants VS Zombies scripting.
I would go the route @drmcw said unless it doesn't need to run code.For the draggable only once, make it so that the clones stamp themselves then delete the clones, and to make the plants functional make an invisible-costumed sprite that goes to the stamps to make them function. As for the sun appearing by the packet, I would suggest putting the generate sun script under when I start as a clone but it's a little harder to identify the problem since we can't see the project. Please share it and give a link.
Can I have a simple explanation. I am using GIFs and clones. Does that help?
I'm trying that script word for word but it's not working.
And thanks for the quick reply.
- BKFighter
-
1000+ posts
Help with Plants VS Zombies scripting.
It probably just needs to some tweaking to fit your game. If you share the project and give us the link we can work it out quickly.I would go the route @drmcw said unless it doesn't need to run code.For the draggable only once, make it so that the clones stamp themselves then delete the clones, and to make the plants functional make an invisible-costumed sprite that goes to the stamps to make them function. As for the sun appearing by the packet, I would suggest putting the generate sun script under when I start as a clone but it's a little harder to identify the problem since we can't see the project. Please share it and give a link.
Can I have a simple explanation. I am using GIFs and clones. Does that help?
I'm trying that script word for word but it's not working.
And thanks for the quick reply.
- MechaDuck
-
10 posts
Help with Plants VS Zombies scripting.
At the start of the discussion I said how this was for a school project. The teacher said the getting stuff off Scratch is fine, getting helped is fine, but getting someone to do it for you, or copying someones work is a step too far. It's ok if you can't help.
- BKFighter
-
1000+ posts
Help with Plants VS Zombies scripting.
Hmm… Maybe I can walk you through some possible bugs. You are creating clones right? You probably want something like this for the ‘spawner’
Also, check to make sure its a ‘local’ (this sprite only must be checked) variable.
This would just get a clone ready to be drug.
Also, check to make sure its a ‘local’ (this sprite only must be checked) variable.
- MechaDuck
-
10 posts
Help with Plants VS Zombies scripting.
Literally just fixed problem 2 as I got your mail. I had on!
Thanks any way though.
Thanks any way though.
- MechaDuck
-
10 posts
Help with Plants VS Zombies scripting.
Still need help with how to, for example, sun to a cloned sunflower.
- MechaDuck
-
10 posts
Help with Plants VS Zombies scripting.
And rounding aswell, so that I can plant them on the squares
Last edited by MechaDuck (April 6, 2016 19:57:47)
- BKFighter
-
1000+ posts
Help with Plants VS Zombies scripting.
I assume you mean having a flower make a sun. Try something like: Still need help with how to, for example, sun to a cloned sunflower.
- MechaDuck
-
10 posts
Help with Plants VS Zombies scripting.
Thank you alot!
And sorry for my typo.
And sorry for my typo.

- MechaDuck
-
10 posts
Help with Plants VS Zombies scripting.
What about a projectile?
Last edited by MechaDuck (April 7, 2016 16:14:18)
- BKFighter
-
1000+ posts
Help with Plants VS Zombies scripting.
You can take their x and y position, divide it by the number of rows/columns, round that number, multiply it by the number you divided, and adjust for where the columns are. So, for a 4x4 grid starting at 10,10 it would look like: And rounding aswell, so that I can plant them on the squares
- BKFighter
-
1000+ posts
Help with Plants VS Zombies scripting.
For pea shooters, have them make a clone. To keep track of what type, have them do this: What about a projectile?
- MechaDuck
-
10 posts
Help with Plants VS Zombies scripting.
How do I decide what MY 10 x 10 would be?
And I've done all the rounding and all that, but when a sunflower clones is placed down, I end up dragging multiple clones. Why?
And I've done all the rounding and all that, but when a sunflower clones is placed down, I end up dragging multiple clones. Why?
Last edited by MechaDuck (April 8, 2016 11:07:36)
- BKFighter
-
1000+ posts
Help with Plants VS Zombies scripting.
Multiple clones must have been created. Scratch updates 30 times per second so user inputs can be activated several times in the code with one push of a button or click. Also, I think my code might have been off, give me a sec to find a better one. How do I decide what MY 10 x 10 would be?
And I've done all the rounding and all that, but when a sunflower clones is placed down, I end up dragging multiple clones. Why?
- BKFighter
-
1000+ posts
Help with Plants VS Zombies scripting.
My bad. It's not row by column, its the actual size of the rows and columns. So if it were 4 pixels wide by 4 pixels tall. Your probably have like 20x20 or 30x30 pixel cells.
- Discussion Forums
- » Help with Scripts
-
» Help with Plants VS Zombies scripting.