From Test-Scratch-Wiki

"Proc" redirects here. For an explanation of procedures, see Procedures.
定義 ()
类别 更多积木
形狀 Modified 半圆形积木

Define () is a 积木 introduced in Scratch 2.0 with a unique, 半圆形积木-like shape that falls under the 更多积木 category. It is used to define custom blocks. This block is unique among the blocks for several reasons, including its lack of appearance in the 积木选择区, its shape and color, and its 'edit' menu when right-clicked. A define block is created each time a new custom block is, appearing on the 程式工作区 of the current 角色, or the 舞台's scripts area if it selected. Deleting a define block is only permitted if there are no instances of the associated custom block in the project.

Every instance of this block creates an instance of the () 积木.

The custom block "edit" menu


Several different incarnations of the define block

In early versions of Scratch 2.0, this block was called "Proc" (an abbreviation of procedure). During this time, the block was the same color as either 控制类积木 or Event/Triggers blocks and had a triangular top (changed from its original Hat shape), two elements which remained even after the block was renamed. In September 2011, the block was brown. The block took its current shape and color in late June 2012.[citation needed]


This block can be used for, for example:

  • Defining a custom block
定義 Ask
詢問 [Rock, paper, or scissors?] 並等待
如果 ((詢問的答案) = [Rock]) 那麼 
  廣播訊息 [rock v]
如果 ((詢問的答案) = [paper]) 那麼 
  廣播訊息 [paper v]
如果 ((詢問的答案) = [scissors]) 那麼 
  廣播訊息 [scissors v]

當 @greenflag 被點擊
Ask :: custom
  • Helping with recurring use of a complicated program
定義 Save
如果 <(Game Level) > [12]> 那麼 
  變數 [☁Person's Game v] 設為 [12]
  詢問 [Keep going?] 並等待
  如果 ((詢問的答案) = [yes]) 那麼 
    廣播訊息 [game v]
    變數 [Player# v] 設為 ((Player#) - (1))
    廣播訊息 [endgame v]

當收到訊息 [savegame v]
Save :: custom
如果 <碰到顏色 [#000000] ?> 那麼 
  Get out of ground :: custom

定義 Get out of ground
y 改變 (1)
如果 <碰到顏色 [#000000] ?> 那麼 
  Get out of ground :: custom
  • Speeding up complicated scripts (such as with the pen)
定義 draw //Make this block run without screen refresh
定位到 x: (-240) y: (-180)
筆跡顏色設為 (0)
重複 (480) 次 
  y 設為 (180)
  y 設為 (-180)
  x 改變 (1)
  筆跡顏色改變 (1)

Edit menu


Numbers, strings, and variables can be inserted into a custom block's name. These can be placed into the procedure script; the inputs are rendered as the parameters in the custom block.

Number Input

Numbers can be inputted into a custom block's name to easily customize the script when it is run. For example, a "jump (height) pixels" block may be made with "height" as the number input. "Height" can be placed into the block's definition, and the number will render as the inputted number in the stack custom block. For example, if you have the following script:

定義 jump (height) pixels
重複 (5) 次 
  y 改變 ((height) / (5))
重複 (5) 次 
  y 改變 ((-1) * ((height) / (5)))

jump (40) pixels :: custom

Then, your custom block would look like the above block.
Whatever number you enter into () will make each "height" in the scripts that number. So if one entered a "5" into the number input and ran the custom block, everywhere in the definition script that contains "height" will input a "5".

Note Note: "height" does not actually, visually change into the inputted number but represents it

String Input

字串 inputs can also be inserted into a custom block. A string input creates parameters in the custom block to enter text. The string that is typed into the custom block is the same string will be rendered where those string inputs are in the definition script while running. Below is an example:

定義 say (text) until space pressed
說出 (text)
等待直到 <[空白 v] 鍵被按下?>
等待直到 <<[空白 v] 鍵被按下?> 不成立>
說出 []

say [] until space pressed :: custom

This is a custom block used to say a message until the space key is pressed, and then stop saying the message. At the very bottom is the actual custom block itself. Whatever string is typed into the perimeters (the []) will figuratively replace the (text) in the definition script above. For example, if one typed "Hello there!" into the custom block, in the definition script where (text) is that string will be represented and rendered there when the block runs.

Boolean Input

布林值 inputs are another input type. Boolean inputs allow for Boolean blocks to be placed inside of them. The value of the Boolean block placed in the input will be used for all instances of the block inside the definition. A common mistake[1][2][3] is that the Boolean block itself is passed into the custom block (so the value will be able to change during the execution of the block) but that is in fact false, the value when the custom block starts executing remains the same throughout the execution of the block.

Below is an example:

定義 eat food <tasty?>
如果 <tasty?> 那麼 
  說出 [Yummy!]

  說出 [I said that I want something tasty! Not this!]

Sometimes, a Boolean value of either true or false needs to specifically be passed into a custom block:

  • Putting no Boolean will make the input "false".
  • Putting a not block will make the input "true".

Run without Screen Refresh

A screen refresh is a shift to the next frame in a script. Between every block in a script is a minuscule wait; if the check box in the "edit" menu of a custom block is selected, the block will run without screen refreshing. That means the block will run in an instant with exactly no wait in-between any blocks. This can be helpful when solving large mathematical operations with very long scripts. While a block with this option selected is executing, sounds may be distorted.



Cookies help us deliver our services. By using our services, you agree to our use of cookies.