How to Define a Reporter Block

Материал из Поле цифровой дидактики

Scratch does not have the ability to define reporter blocks, but they can be simulated using variables.

Creating the Custom Block and Variable

define . . . // Change . . . to the description you want. Add required parameters if needed.
. . . :: grey
set [return v] to (. . . :: grey)

Example

// create a custom multiplication block
define Multiply (n1)(n2)
set [return v] to ((n1) * (n2))
stop [this script v]
when flag clicked
ask [What is the first number?] and wait
set [num1 v] to (answer)
ask [What is the second number?] and wait
set [num2 v] to (answer)
Multiply (num1)(num2)
say (return)

You could also create a boolean:

define does (n1) equal (n2)?
set [return v] to <(n1) = (n2)>
stop [this script v]

Then you could insert it into an if statement

if <(return) = [true]> then
Do something :: grey
end