Discuss Scratch

MechaDuck
New Scratcher
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…
drmcw
Scratcher
1000+ posts

Help with Plants VS Zombies scripting.

1. Use a variable. Assuming you're using clones
whenIstartasaclonesetalready dropped?to0 make variable local (for this sprite only)whenthisspriteclickedifalreadydropped?=0thenrepeatuntilnotmousedown?gotomouse-pointersetalready dropped?to1

2 you need to share the project to work that out
Koopakid6000
Scratcher
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
New Scratcher
10 posts

Help with Plants VS Zombies scripting.

Koopakid6000 wrote:

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
Scratcher
1000+ posts

Help with Plants VS Zombies scripting.

MechaDuck wrote:

Koopakid6000 wrote:

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 would go the route @drmcw said unless it doesn't need to run code.
MechaDuck
New Scratcher
10 posts

Help with Plants VS Zombies scripting.

BKFighter wrote:

MechaDuck wrote:

Koopakid6000 wrote:

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 would go the route @drmcw said unless it doesn't need to run code.

I'm trying that script word for word but it's not working.
And thanks for the quick reply.
BKFighter
Scratcher
1000+ posts

Help with Plants VS Zombies scripting.

MechaDuck wrote:

BKFighter wrote:

MechaDuck wrote:

Koopakid6000 wrote:

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 would go the route @drmcw said unless it doesn't need to run code.

I'm trying that script word for word but it's not working.
And thanks for the quick reply.
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.
MechaDuck
New Scratcher
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
Scratcher
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’
whenclickedhidewhenIreceivecard triggercreatecloneofmyself
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
New Scratcher
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.
MechaDuck
New Scratcher
10 posts

Help with Plants VS Zombies scripting.

Still need help with how to, for example, sun to a cloned sunflower.
MechaDuck
New Scratcher
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
Scratcher
1000+ posts

Help with Plants VS Zombies scripting.

MechaDuck wrote:

Still need help with how to, for example, sun to a cloned sunflower.
I assume you mean having a flower make a sun. Try something like:
whenIstartasaclonewaituntildropped=1foreverwaithowever manysecscreatecloneofsunMake sure you have a sprite like sun, that spawns suns in randomly. You can then make a clone of that from here
MechaDuck
New Scratcher
10 posts

Help with Plants VS Zombies scripting.

Thank you alot!
And sorry for my typo.
MechaDuck
New Scratcher
10 posts

Help with Plants VS Zombies scripting.

What about a projectile?

Last edited by MechaDuck (April 7, 2016 16:14:18)

BKFighter
Scratcher
1000+ posts

Help with Plants VS Zombies scripting.

MechaDuck wrote:

And rounding aswell, so that I can plant them on the squares
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:
roundxposition-10/4*4+10
BKFighter
Scratcher
1000+ posts

Help with Plants VS Zombies scripting.

MechaDuck wrote:

What about a projectile?
For pea shooters, have them make a clone. To keep track of what type, have them do this:
switchcostumetoprojectilecreatecloneofmyselfswitchcostumetopeashooterwhenIstartasacloneifcostume#=# of projectile costumethenforeverchangexby10...blahblahblahdetectioncodemakesuretodeletecloneselse...runplacementcode
MechaDuck
New Scratcher
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?

Last edited by MechaDuck (April 8, 2016 11:07:36)

BKFighter
Scratcher
1000+ posts

Help with Plants VS Zombies scripting.

MechaDuck wrote:

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?
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.
BKFighter
Scratcher
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.
roundxposition-10/widthorheight*widthorheight+10

Powered by DjangoBB