首页 > 其他 > 详细

Breakable loop in Scratch

时间:2019-02-28 18:25:57      阅读:171      评论:0      收藏:0      [点我收藏+]

Breakable loop in Scratch

https://stackoverflow.com/questions/30682144/breakable-loop-in-scratch

 

Breakable loop in Scratch ?

How do you make a breakable loop in Scratch? I‘m using Scratch 2.0 and can‘t find any good way to make a loop breakable, from inside of the loop itself.

 

Disclaimer:

There is no perfect way to do it. If you can possibly stand this true fact then feel free to continue.


There are a few different ways you could do it.

With repeat until

The first and most simple one follows this:

技术分享图片

But this isn‘t technically part of the script - it‘s just repeating until some value returns true.

With a custom block (stop this script)

In order to do it inside of the script, you‘ll need to use a sneaky little trick with custom blocks.

Create a custom block called whatever you want - but probably along the lines of "breakable loop". Inside of it, create this script:

技术分享图片

By using stop script we are breaking out of the script that is currently running - which, according to Scratch, is the custom block.

 

See the result! (as scratchblocks)    http://scratchblocks.github.io

技术分享图片

 

With broadcast and wait

You could also use a broadcast-and-wait method, very similar to above:

技术分享图片

Though I highly suggest you don‘t use this method, as if any other sprites have breakable loops you‘ll need to rename each one, which can be tedious after using a lot of loops in a lot of sprites!

 

======================= End

 

Breakable loop in Scratch

原文:https://www.cnblogs.com/lsgxeva/p/10452080.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!