Printing Messages in Alert or Console
-
Description
Very often, we need to print out some text messages. For example, we can show the user some information in a dialog box (the alert window), or log some information in the console to debug our program. Note that this is different from printing inside the stage window.
Showing an Alert Message
To show an alert message, you can use this block from the Control category:
Note that in the alert mode, the code blocks below this block will not run until you click “OK” on the alert window. Therefore, alert messages are great if you want to force the user to acknowledge something before continuing, or if you want to show the user some information that he or she has to read first.
Parameters
- Message: You can write any text message in the input space, including emoji symbols.
- Alert: You need to select “alert” in the dropdown
- Color: The color will be ignored for alert messages, since all alert messages have to be in black.
Printing a Message to the Console
The console is a small window at the bottom of the playground, next to the backpack. You can open or close it like this.
To print a message in this console, you need to select “console” in the “print” block, and you can also specify the color of this message. When you print a new message, a red counter will show up to alert you.
Scrolling Down the Console
When you click the green flag button, all the messages in the console will be cleared out. When there are many messages, you can scroll down the console to view them. You can also check the “autoscroll” checkbox, so the console will scroll down to the latest message automatically.