How to Define a Reporter Block: различия между версиями

Материал из Поле цифровой дидактики
м (1 версия импортирована)
 
Строка 1: Строка 1:
{{NotUseful|Minor enough that it should just be a section in [[My Blocks]]|date=April 2022}}
Scratch does not have the ability to define [[reporter]] blocks, but they can be simulated using [[variable]]s.
Scratch does not have the ability to define [[reporter]] blocks, but they can be simulated using [[variable]]s.



Текущая версия на 15:57, 21 июля 2022

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