Fifth Scenario: Sensing & Operators
Quick References for all Sensing blocks
touching (mouse-pointer/edge/sprite)?: This block checks if the sprite is touching the mouse pointer, edge, or another sprite. It can be used for interactive elements like buttons.
touching color (color)?: This block checks if the sprite is touching the specified color on the screen.
color (color) is touching (color)?: This block checks if one specific color on the sprite is touching another color. It’s useful for more precise collision detection, like in mazes.
distance to (mouse-pointer/sprite): This block reports the distance from the sprite to the mouse pointer or another sprite, which can be used for follow-the-mouse effects or distance-based triggers.
ask (text) and wait: This block prompts the user with a question and waits for an input before the script continues.
answer: This reporter block holds the latest answer given by the user to an "ask" block.
key (key name) pressed?: This block checks if the specified key is currently being pressed.
mouse down?: This block checks if the mouse button is currently being pressed down.
mouse x and mouse y: These reporter blocks give the current x (horizontal) and y (vertical) position of the mouse cursor on the stage.
set drag mode [draggable/ not draggable]: This block decides whether the sprite can be dragged with the mouse or not.
draggable: the sprite can be clicked and moved around the stage using the mouse.
not draggable: the sprite cannot be moved with the mouse, fixed in place unless controlled by other scripts.
loudness (check box to show): This reporter block gives the current loudness of the sound picked up by the computer's microphone.
timer (check box to show): This reporter block reports the amount of time since the project started or since the timer was last reset.
reset timer: This block sets the timer back to 0 seconds.
[variable] of (sprite): This block is a reporter block that can get various types of information from the stage or other sprites.
current [time] (check box to show): This reporter block reports the current time from the system's clock. The dropdown can be used to report other time units such as month, day, hour, etc.
days since 2000: This reporter block calculates the number of days that have passed since January 1st, 2000. This is often used for time-stamping data or for measuring time intervals within a project.
username (check box to show): This reporter block gives the username of the person logged into Scratch. This block can be used to personalize projects or for data tracking purposes.
Quick References for all Operators blocks
+ (Addition): This block adds two numerical values together. You can input numbers, variables, or a combination of both.
- (Subtraction): This block subtracts the bottom value from the top value. You can input numbers, variables, or a combination of both.
* (Multiplication): This block multiplies two values. You can input numbers, variables, or a combination of both.
/ (Division): This block divides the left value by the right value. You can input numbers, variables, or a combination of both.
pick random (number) to (number): This block generates a random integer between the two specified numbers, inclusive. For example, this block would give a random number between 1 and 10, including 1 and 10.
> (Greater than), < (Less than), = (Equal): These blocks are used for comparing two values. They will report true if the condition is met (e.g., if the first value is greater than, less than, or equal to the second value), or false otherwise.
<bool> and <bool>, <bool> or <bool>, not <bool>: These are logical operators used to combine or invert boolean expressions. They are fundamental in constructing more complex logical conditions.
join (text) (text): This block combines two strings of text into one. For example, "apple" and "banana" would result in "applebanana."
letter (number) of (text): This block reports a specified character from a string. For instance, "letter 1 of 'apple'" would return "a," the first letter of "apple."
length of (text): This block gives the number of characters in the given string. For "apple," it would return 5.
(text) contains (text)?: This block checks if the first string contains the second string and reports true or false. For example, it checks if "apple" contains the letter "a," which would return true.
(number) mod (number): This block calculates the remainder of a division of two numbers. It's the modulo operation, so "10 mod 3" would result in 1.
round (number): This block rounds a number to the nearest whole number. For example, "round 3.14" would give you 3.
[math] of (number): This block calculates the value of a number after a math operation. For instance, "abs of -5" would return 5.
Sensing
Operators
Boolean< blocks >
These <diamond shape blocks> are <boolean> blocks that check a condition and return True or False. You probably see some examples in the Event Session already. Imaging you are asking your sprite or computer Yes or No questions "Do you touch the mouse pointer?", "Did someone press the space key? ", "Is this number equal to 50? "or "Does the word apple contain an A?". The answers to these questions can only be Yes/True or No/False, and there is no status in between. These blocks represent the answer to the question at the moment the block ran.
Boolean Operators
Boolean operators calculate a new boolean with boolean values.
<boolean A> and <boolean B> can only be True when both of them are True, otherwise it will be False.
<boolean A> or <boolean B> will be True when either of them are True, otherwise it will be False.
Not <Boolean B> will flip B from Ture to False.
touching (mouse/edge/sprite/color)?
color (color) is touching (color)?
These blocks only detect whether the sprite with the code block has contact with the mouse, edge, another sprite, or a certain color.
Example:
repeat until <touching color (red)>:
glide (0.5) secs to mouse-pointer
if color(orange) is touching color(red):
(the first color need to be from the sprite)
Click the green flag to start.
Click the cat to create a clone(copy) of it.
Wait for one clone that touches the edge. Click the mouse anywhere, it will switch to Tree background. Here the cat will move with your mouse pointer to find the flower. After getting the flower(touching color red), it will stop all scripts and end this game.
Sensing
Value ( blocks )
These (oval shape blocks) are (value) blocks that store a number or a string(text). This rule also applies to other oval shape blocks in Scratch.
The sensing blocks will get the value automatically either from your device (mouse, microphone, and time) or from your game (answers, backdrop, username).
The operator blocks require you to choose one or more values to calculate a new value as the result of an expression. For example, (pick random (1) to (10)) will give you a number from 1 to 10 (including 1 and 10) randomly. Join(apple)(banana) will give you a new string "applebanana".