Discuss Scratch

Boomdriver
Scratcher
6 posts

How do i get a script to stop when it is already running

I have the following scripts already in my farming game but I can't get it to work.

when I receive [grow]
if <(costume [name]) = [wheat 1]> then
repeat until <(costume [name]) = [wheat 7]>
wait (2) secs
next costume
repeat until <touching [ shovel] ?>
if <touching [ shovel] ?> then
stop [all ]
end
end
end
end

When i start it, it goes to wheat 2 but then stops while the shovel still works. I am trying to have it where when it is growing i can have the shovel touch it and it will stop.

https://scratch.mit.edu/projects/1126123439/

Last edited by Boomdriver (Feb. 25, 2025 16:02:33)

cs3707537
Scratcher
41 posts

How do i get a script to stop when it is already running

Can you send the link to the project? It makes sense, except for the fact that it doesn't[ touch anything because it's not moving. Are you trying to have it just stop by touching itself? If so, you might need to make another sprite.
Boomdriver
Scratcher
6 posts

How do i get a script to stop when it is already running

cs3707537 wrote:

Can you send the link to the project? It makes sense, except for the fact that it doesn't[ touch anything because it's not moving. Are you trying to have it just stop by touching itself? If so, you might need to make another sprite.

Yes i have edited it to have the link to the project although it is not done. I am trying to have it where when it is growing i can have the shovel touch it and it will stop.

Last edited by Boomdriver (Feb. 25, 2025 15:06:07)

AidanandMommy
Scratcher
12 posts

How do i get a script to stop when it is already running

Easy: Change the “stop all” to “stop this script.” Then when you want to start growing again, start the code again with a broadcast or something.
Boomdriver
Scratcher
6 posts

How do i get a script to stop when it is already running

AidanandMommy wrote:

Easy: Change the “stop all” to “stop this script.” Then when you want to start growing again, start the code again with a broadcast or something.

Well i currently have it as all to make sure it works and i have it start from a broadcast but it won't grow
10goto10
Scratcher
1000+ posts

How do i get a script to stop when it is already running

The “repeat until touch shovel” has locked up the script and won’t let execute any more “next costume” commands. What did you want to do with the repeat block that has the if block inside of it?
Boomdriver
Scratcher
6 posts

How do i get a script to stop when it is already running

10goto10 wrote:

The “repeat until touch shovel” has locked up the script and won’t let execute any more “next costume” commands. What did you want to do with the repeat block that has the if block inside of it?


I wanted it to stop the growing process and set it back to costume 0
deck26
Scratcher
1000+ posts

How do i get a script to stop when it is already running

The ‘if touching shovel’ immediately follows a ‘repeat until touching shovel’ so unless the sprite touches the shovel in the split second between those blocks being executed it will never get to the stop all.
Boomdriver
Scratcher
6 posts

How do i get a script to stop when it is already running

deck26 wrote:

The ‘if touching shovel’ immediately follows a ‘repeat until touching shovel’ so unless the sprite touches the shovel in the split second between those blocks being executed it will never get to the stop all.

I tried that but now it just grows back every time i dig it up
10goto10
Scratcher
1000+ posts

How do i get a script to stop when it is already running

One way to stop a script that is started with a broadcast is to do another broadcast that has been changed to start out with a test to see if it should run.

Your script that tests to see if the farmplot1 sprite is touching the shovel could do a
set [Abort Growing v] to [true]
broadcast [Growing v]
And the
when I receive [ Growing v]
script would the start out with
if <(Abort Growing) = [true]> then
stop [This script v]
end
cs3707537
Scratcher
41 posts

How do i get a script to stop when it is already running

Boomdriver wrote:

cs3707537 wrote:

Can you send the link to the project? It makes sense, except for the fact that it doesn't[ touch anything because it's not moving. Are you trying to have it just stop by touching itself? If so, you might need to make another sprite.

Yes i have edited it to have the link to the project although it is not done. I am trying to have it where when it is growing i can have the shovel touch it and it will stop.
Sorry, I didn't see the link!
Boomdriver
Scratcher
6 posts

How do i get a script to stop when it is already running

10goto10 wrote:

One way to stop a script that is started with a broadcast is to do another broadcast that has been changed to start out with a test to see if it should run.

Your script that tests to see if the farmplot1 sprite is touching the shovel could do a
set [Abort Growing v] to [true]
broadcast [Growing v]
And the
when I receive [ Growing v]
script would the start out with
if <(Abort Growing) = [true]> then
stop [This script v]
end


I added in what you wrote and it worked, thank you.

Powered by DjangoBB