This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-05-11 12:44:01

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Halting a running code

Hi
I've got a script and I've been playing with it for a while (it's for a TD game) and I'm trying to find a way to stop the enemies moving after they die, so far I've tried a few things, this is a sample of the code:
[scratchblocks]
when gf clicked
forever if <(health) > [0]>
repeat ((330) / (speed)
move (speed) steps
end
end
[scratchblocks]
so far it isn't working, the repeat move script is repeated with turns for every corner
Any ideas?


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#2 2012-05-11 12:47:09

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Halting a running code

when gf clicked
forever if <(health) > [0]>
repeat ((330) / (speed)
move (speed) steps
end
end
Fixed


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#3 2012-05-12 01:49:28

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: Halting a running code

You will have to use the stop script block. It is at the end of the yellow colored script parts in the program.


Why are the secret organizations getting all the attention?  mad

Offline

 

#4 2012-05-12 04:46:58

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: Halting a running code

zammer990 wrote:

when gf clicked
forever if <(health) > [0]>
repeat ((330) / (speed))
move (speed) steps
end
end
Fixed

Now it's really fixed. Your "repeat" block was faulty.  tongue


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#5 2012-05-12 05:22:20

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Halting a running code

Thanks  for the help, I found a rather tedious way of doing it with the stop script block but I wish they'd make the "stop all in sprite" block  smile


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#6 2012-05-12 09:02:34

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Halting a running code

jontmy00 wrote:

zammer990 wrote:

when gf clicked
forever if <(health) > [0]>
repeat ((330) / (speed))
move (speed) steps
end
Fixed

Now it's really fixed. Your "repeat" block was faulty.  tongue

Triple fixed (got rid of bump at the end  tongue )

@"stop all scripts in sprite" block: I think somebody's made that a suggestion.  But you're right, it would be quite useful.  As for the forever script, I would use a repeat until loop:

repeat until<not <(health) > (0)>>
move (speed) steps
end
I'm a little confused as to why you had a "repeat" block within a forever loop though  hmm


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#7 2012-05-12 09:08:17

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Halting a running code

MoreGamesNow wrote:

jontmy00 wrote:

zammer990 wrote:

when gf clicked
forever if <(health) > [0]>
repeat ((330) / (speed))
move (speed) steps
end
Fixed

Now it's really fixed. Your "repeat" block was faulty.  tongue

Triple fixed (got rid of bump at the end  tongue )

@"stop all scripts in sprite" block: I think somebody's made that a suggestion.  But you're right, it would be quite useful.  As for the forever script, I would use a repeat until loop:

repeat until<not <(health) > (0)>>
move (speed) steps
end
I'm a little confused as to why you had a "repeat" block within a forever loop though  hmm

Yea, I got rid of that after I fixed it, using repeat until simply halts it after the code finishes, not mid way


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#8 2012-05-12 12:37:40

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: Halting a running code

You could do

if <<(health) = (0)> or <(health) < (0)>>
 stop script
end
in the middle of a loop.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#9 2012-05-12 14:29:15

turkey3
Scratcher
Registered: 2011-12-04
Posts: 500+

Re: Halting a running code

In most tower defense games, the enemies stop moving either when they reach the end or are beat. Also, you will need to make a sprite for the end point. This would work:

When gf clicked
Wait until <(timer) = [time you want it to move]> // this may vary
Repeat until <<(health) = [0]> or <touching [end point v]?>>
Do movement scripts
End
hide
The scripts may vary.

Last edited by turkey3 (2012-05-12 14:29:36)

Offline

 

#10 2012-05-12 16:56:11

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: Halting a running code

Repeat until seems to continue it's iteration after the conditions are false, and stop once it finished. I've solved the problem now anyway


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

Board footer