调试——断点
-
先修科目
什么是“断点”?
“断点”就是程序可以“休息一下”。也就是说,程序将暂停,当你让它继续的时候再继续。程序暂停以后,你可以做很多事情来检查项目是否运行正常,比如检查变量的值、角色的位置等等。
积木:“断点”
加入断点方法:你想让项目在哪里暂停,就在哪里插入这个积木:
https://cdn.creaticode.com/scratch-gui-projects/forum/27433ce8-9bd8-4fa9-a6db-54c3441beaba.png" width="80" style="filter: drop-shadow(0.35rem 0.35rem 0.4rem rgba(0, 0, 0, 0.5));">
在项目中,你插入多少个断点都可以,通常情况下只需要用一个或几个。
按钮:“调试”
如果你点击绿旗按钮运行程序,所有断点都会被忽略。若要激活断点,需要在“调试模式”运行程序,方法就是点击蓝色箭头按钮:

在调试模式中,程序每当遇到断点就会暂停。只需再次点击蓝色箭头按钮,即可使程序继续运行。
示例1
在这个示例中,有2个断点,那么,程序运行完第一个断点之前的积木之后就会暂停。当我们再次点击蓝色箭头按钮,程序继续运行至第二个断点。
https://cdn.creaticode.com/scratch-gui-projects/forum/1e2ce772-d76d-42e5-b379-566870211294.gif" width="600" style="border-radius: 5px; border: 1px solid #29622d;">
示例2
你还可以把断点放入积木“如果”,以便于仅当满足特定条件时才会暂停程序。
在这个示例中,我们让小狗一直向下走,仅当小狗碰到苹果时才暂停循环:
https://cdn.creaticode.com/scratch-gui-projects/forum/46e484cf-3cb6-4da7-b319-601edb1b6efc.gif" width="700" style="border-radius: 5px; border: 1px solid #29622d;">
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login