提供:Japanese Scratch-Wiki

このきじは ひらがなでよめません。ごめんなさい。編集者向け:作成する
この画像の赤い部分を押すとデバッグの画面が開く
デバッグのボタン

Debug(デバッグ)とは、スクリプトのデバッグ(バグを取り除くこと)に関するヘルプを表示するダイアログである。2024年12月16日のScratch 3.0のメジャーアップデートの一部として追加された。

ユーザーインターフェースのナビゲーションバーにある「Debug」のボタンをクリックすると、ユーザーがプロジェクト内の問題を理解するのに役立つさまざまなヒントを含む13の項目からなるダイアログが開く。このダイアログでは、ユーザーがコード内でミスを犯した可能性のあるさまざまな方法を説明し、タイミング、サウンドチェックポイント、コードへのコメントの追加など、スクリプトを修正するためのさまざまな方法がかかれている。

本文

Debugは、まだ日本語に訳されていない。Debugの原文と非公式訳を以下に記す。

原文

Read Aloud

As you read your code aloud, think from the computer’s perspective.

  • Are you including steps that aren’t there?
  • Are your instructions clear?
  • If something needs to be reset each time the program has run, are those instructions included?


Break It Down

Separate the blocks into smaller chunks (or sequences), and click to see what each sequence does.

Once the smaller sequences work as you expect, add them back into the main program.

The process is called decomposition.


Slow It Down

The computer runs your program so quickly it can be hard to follow with your eyes.

Add temporary “wait” or “wait until” blocks to slow down the sequence. This gives you time to process if a piece worked or not.

Remove these wait blocks once your code works.


Add Sound Checkpoints

Similar to the Slow It Down strategy, you can add different sounds with the “play until done” block at key points to test your sequence.

If a sound doesn’t play, your bug may be before this block. If the sound plays, the bug is probably after this block.

Remove the sounds once your code works.


Tinker with Block Order

Try adjusting the order/sequence of the blocks.

What needs to happen first? What happens second? Do values or sprites need to reset before the next piece of code runs? Try using blocks inside a loop or conditional statement, versus outside a loop or conditional statement.


To Loop or Not to Loop

If using Control blocks like "forever" and "repeat", check that all blocks inside a loop should be there, or if a block (like “wait”) is missing to reset the action or adjust the timing. Do you want your loop to run forever or for a certain number of times? Should something stop the looping?

Perhaps you aren't using a loop when you should be? For instance, if you are using a conditional statement block like "if then," does the program only need to check if it is true or false once? Or does it need to check continuously, in which case, you would want to place your conditional statement inside a forever loop?


Think About Timing & Parallelism

Do you have multiple events trying to run at the same time? If two sequences are programmed to start at the same time, you can get unpredictable behavior.

Add small waits, broadcasts, or user interaction (like clicking or pressing a key) to see if this affects the result.


Think About Block Options

Is there a similar but different block you can use?

Some blocks look similar but can behave differently, such as “set” vs “change” or “play until done” vs “start.”

Try using a similar block in place of what you have, and see if this affects the result.


Check the Values

If you are using variables or reporter blocks, check the value at the moment the code sequence is run.

  • Do/should all the sprites control a variable, or should only one sprite have control?
  • Where is the value reset? Where is it changed?


Check Code Sequence

Check that your code sequence is attached to the correct sprite or the backdrop, if appropriate.

If you need to move your code to another sprite, click and drag it until you are hovering over the correct sprite. Release it once the sprite wiggles.

You can also use your Backpack (bottom of screen) to store and move your code or assets.


Comment Your Code

Adding comments to your code can help others looking at your code to understand it. It can also help you remember how your code works when you come back to it later.

Right click on script area to “Add Comment.” Use everyday language to explain what a block, or small sequence of blocks, does.


Take a Break, Step Away

Sometimes, spending too much time focused on an issue can be counterproductive and frustrating.

Take a break and step away from the screen to clear your mind. After some rest, focusing on something else, or getting some water, you can approach the problem with fresh eyes.


Ask for Help

If you are still stuck, you can ask for help from a peer. Try finding a debugging/help studio and share your project, asking for help in a comment or the project notes.

Ask one to three people to try your code, as different people may have different perspectives or solutions!


非公式訳

声に出して読む

コードを声に出して読むときは、コンピューターの視点から考えます。

  • 存在しない手順を含めていますか?
  • 指示は明確ですか?
  • プログラムが実行されるたびに何かをリセットする必要がある場合、その手順は含まれていますか?

分解する

ブロックを小さなチャンク (またはシーケンス) に分割し、クリックして各シーケンスの動作を確認します。

小さなシーケンスが期待どおりに動作したら、メイン プログラムに戻します。

この過程は分解と呼ばれます。

ゆっくりやる

コンピューターはプログラムを非常に速く実行するので、目で追うのが難しくなる場合があります。

一時的な() 秒待つまたは() まで待つブロックを追加して、シーケンスを遅くします。これにより、ピースが機能したかどうかを処理する時間ができます。

コードが動作したら、これらの待機ブロックを削除します。

サウンドチェックポイントを追加する

「ゆっくりやる」法と同様に重要なポイントで、終わるまで () の音を鳴らすブロックを使用してさまざまなサウンドを追加し、シーケンスをテストできます。

サウンドが再生されない場合は、バグはこのブロックの前にある可能性があります。サウンドが再生される場合は、バグはこのブロックの後にある可能性があります。

コードが機能したらサウンドを削除します。

ブロックの順序をいじる

ブロックの順序/シーケンスを調整してみてください。

まず何が起こる必要がありますか? 次に何が起こるでしょうか? 次のコードが実行される前に、値またはスプライトをリセットする必要がありますか? ループや条件文の外側ではなく、ループや条件文の内側でブロックを使用してみてください。

ループするかしないか

ずっと」や「繰り返す」などの制御ブロックを使用する場合は、ループ内のすべてのブロックが存在するか、またはアクションをリセットしたりタイミングを調整したりするためのブロック(「待つ」など)が欠落していないかを確認します。ループを永久に実行しますか、それとも特定の回数だけ実行しますか。ループを停止するものはありますか。

おそらく、ループを使用するべきときに使用していないのではないでしょうか。たとえば、「もし () なら」のような条件文ブロックを使用している場合、プログラムは true か false かを1回だけ確認する必要がありますか。それとも、継続的に確認する必要がある場合、条件文を永久ループ内に配置することになりますか。

タイミングと並列性について考える

複数のイベントを同時に実行しようとしていますか? 2 つのシーケンスが同時に開始するようにプログラムされている場合、予期しない動作が発生する可能性があります。

短い待機、ブロードキャスト、またはユーザー操作 (クリックやキーの押下など) を追加して、結果に影響するかどうかを確認します。

ブロックオプションについて考える

類似しているが異なるブロックを使用することはできますか?

一部のブロックは「設定」と「変更」、または () の音を鳴らす終わるまで () の音を鳴らすのように、見た目は似ていますが動作が異なる場合があります。

既存のブロックの代わりに同様のブロックを使用して、結果に影響があるかどうかを確認してください。

値を確認する

変数または値ブロックを使用している場合は、コード シーケンスが実行された時点での値を確認します。

  • すべてのスプライトが変数を制御する必要がありますか、それとも1つのスプライトだけが制御する必要がありますか?
  • 値はどこでリセットされますか? どこで変更されますか?

コードシーケンスを確認する

適切な場合は、コード シーケンスが正しいスプライトまたは背景にアタッチされていることを確認します。

コードを別のスプライトに移動する必要がある場合は、正しいスプライトの上にマウスを移動するまでクリックしてドラッグします。スプライトが揺れたらマウスを放します。

バックパック(画面下部)を使用して、コードやアセットを保存および移動することもできます。

コードにコメントを付ける

コードにコメントを追加すると、他の人がコードを理解しやすくなります。また、後でコードに戻ったときに、コードの動作を思い出すのにも役立ちます。

スクリプト領域を右クリックして「コメントを追加」します。日常的な言葉を使って、ブロックまたはブロックの小さなシーケンスが何を行うかを説明します。

休憩する、離れる

場合によっては、問題に集中して時間をかけすぎると逆効果になり、イライラしてしまうことがあります。

休憩して画面から離れて頭をすっきりさせましょう。少し休んだり、他のことに集中したり、水を飲んだりすると、新鮮な目で問題に取り組むことができます。

助けを求める

それでも問題が解決しない場合は、仲間に助けを求めることができます。デバッグ/ヘルプ スタジオを見つけてプロジェクトを共有し、コメントまたはプロジェクトの情報で助けを求めてください。

人によって視点や解決策が異なる可能性があるため、1~3人にコードを試してもらいましょう。

関連項目

Cookieは私達のサービスを提供するのに役立ちます。このサービスを使用することにより、お客様はCookieの使用に同意するものとします。