本文件提供了輸入驗證的指南,並管理各種輸入類型,如顏色輸入、按鈕、複選框、文字區域、選項列表、文件輸入和數字輸入。
輸入驗證
驗證佈局中的輸入
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_validateInputs\"/></xml>"}
這用於檢查佈局中的輸入是否有效。
參數: 屏幕專案
輸出: 布林值 (True/False)
範例代碼:
使用一個 if-else 條件檢查輸入。
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_validateInputs\"><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">validation</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">The text is valid.</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">validation</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">The text is not valid.</field></shadow></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>resultButton</variable><variable>validation</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextInput\"><field name=\"type\">TextInputType.URL</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Show Result</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">validation</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">validation</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><statement name=\"HANDLER\"><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_validateInputs\"><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">validation</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">The text is valid.</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">validation</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">The text is not valid.</field></shadow></value></block></statement></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
當輸入有效時,輸出:

當輸入無效時,輸出:

生成顏色輸入
創建顏色輸入
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createColorInput\"/></xml>"}
這用於在輸入中創建顏色。
參數: N/A
輸出: 屏幕專案
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>colorInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">colorInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createColorInput\"/></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">colorInput</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
輸入:

您可以修改內部的顏色:

按鈕
生成按鈕
“創建”按鈕
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow></value></block></xml>"}
這用於創建新按鈕。
參數: 顯示字串:String
輸出: 按鈕
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>btn1</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">btn1</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Button</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">btn1</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
輸出:

控制點擊
在控制上按兩下
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value></block></xml>"}
此塊用於按鍵時,它將執行一些操作。
參數: 屏幕專案
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value><statement name=\"HANDLER\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">text</field></block></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>button</variable><variable>text</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">button</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Button</field></shadow></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">text</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">Hello</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value><statement name=\"HANDLER\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">text</field></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
當按鍵時,它將顯示變數文本。
輸出:

點擊按鈕後:

「設置文字開啟」 按鈕
按鈕設置內容
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_Button_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow></value></block></xml>"}
此塊用於在按鈕內設置文字。
參數:
- 螢幕專案(輸入控制項)
- 顯示設置:字串
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>button</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">button</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Button</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value><statement name=\"HANDLER\"><block type=\"Control_Button_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">button</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">You clicked this button.</field></shadow></value></block></statement></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
在按鍵之前,輸出:

點擊「按鈕」後,輸出:

複選框
生成複選框
“創建”複選框
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createCheckbox\"/></xml>"}
這用於創建新的複選框。
參數: N/A
輸出: 複選框
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>createCheckBox</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createCheckBox</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createCheckbox\"/></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createCheckBox</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
輸出:

按下複選框後:

選取框的預設設置
複選框勾選 false
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_Checkbox_setChecked\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkbox</field></block></value><value name=\"isChecked\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></xml>"}
這個塊用於設置預設複選框是否勾選。
參數:
- 螢幕專案(輸入控制項)
- 顯示設定:布爾值 (True/False [Default])
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>checkBox</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">checkBox</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createCheckbox\"/></value><next><block type=\"Control_Checkbox_setChecked\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkBox</field></block></value><value name=\"isChecked\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">checkBox</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
當將複選框設置為 false 時,輸出:

當將複選框設置為 true 時,輸出:

選取選取框是否被選取
選取框處於選取狀態
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_Checkbox_isChecked\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkbox</field></block></value></block></xml>"}
此塊用於檢查複選框是否被點擊。
參數: 螢幕專案(輸入控制項)
輸出: 布林值 (True/False)
範例代碼:
您可以使用 while 循環結合 if-else 條件來顯示結果。
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_Checkbox_isChecked\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkBox</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkChecked</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">It is clicked.</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkChecked</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">It isn't clicked.</field></shadow></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>checkBox</variable><variable>checkChecked</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">checkBox</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createCheckbox\"/></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">checkBox</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">checkChecked</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">checkChecked</field></block></value><next><block type=\"device_while\"><value name=\"COND\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><statement name=\"DO\"><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_Checkbox_isChecked\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkBox</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkChecked</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">It is clicked.</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkChecked</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">It isn't clicked.</field></shadow></value></block></statement><next><block type=\"Task_sleep\"><value name=\"ms\"><shadow type=\"math_number\"><field name=\"NUM\">500</field></shadow></value></block></next></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
注意:您必須使用 “pause ms” 在 while (true) 循環內阻塞。 否則,它將具有無限循環,並且此 Web 應用程式將崩潰。
如果未按下複選框, 則輸出:

按下複選框時,輸出:

文本區域
生成文字區域
創建文字區域
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createTextArea\"/></xml>"}
這用於創建新的文字區域。
參數: 顯示設置:字串
輸出: 屏幕專案
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>textArea</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">textArea</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextArea\"/></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">textArea</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
輸出:

您可以在文字區域內鍵入內容:

輸入類型正確的文本
創建類型為
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createTextInput\"><field name=\"type\">TextInputType.Text</field></block></xml>"}
此塊用於告訴使用者輸入正確的類型。
參數: 顯示設置:文本(預設)/電子郵件/URL
輸出: 屏幕專案
範例代碼:
將類型設定為文字時,輸出:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>createInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextInput\"><field name=\"type\">TextInputType.Text</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createInput</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
將類型設定為電子郵件時,輸出:

將類型設定為 URL 時,輸出:

輸入控制驗證
輸入控制驗證輸入
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_ChangeableInputControl_validateInput\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></xml>"}
此模組用於檢查輸入類型是否正確。
參數: 螢幕專案(輸入控制項)
輸出: 布爾值 (True/False)。
範例代碼:
使用這些塊來檢查使用者是否在打字。
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_ChangeableInputControl_validateInput\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkInput</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Typing something</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkInput</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Please input correct type</field></shadow></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>inputControl</variable><variable>checkInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">inputControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextInput\"><field name=\"type\">TextInputType.Email</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">checkInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">checkInput</field></block></value><next><block type=\"device_while\"><value name=\"COND\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><statement name=\"DO\"><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_ChangeableInputControl_validateInput\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkInput</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Typing something</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkInput</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Please input correct type</field></shadow></value></block></statement><next><block type=\"Task_sleep\"><value name=\"ms\"><shadow type=\"math_number\"><field name=\"NUM\">500</field></shadow></value></block></next></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
輸出:

輸入一些不正確的格式後,輸出:

輸入控制限制
需要輸入控制 false
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_ChangeableInputControl_setInputRequired\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"isRequired\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></xml>"}
如果該值設置為 true,則此塊會限制使用者輸入該值。
參數:
- 螢幕專案(輸入控制項)
- 顯示設定:布爾值 (True/False [Default])
輸出: 布爾值 (True/False)。
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>inputControl</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">inputControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextInput\"><field name=\"type\">TextInputType.Email</field></block></value><next><block type=\"Control_ChangeableInputControl_setInputRequired\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"isRequired\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
當變數要求設置為 false 時,輸出:

當變數要求設置為 true 時,輸出:

更改輸入時有事件
輸入控制更改時
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_ChangeableInputControl_onInputChanged\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></xml>"}
此區塊用於當使用者在文字框中輸入內容後按下鍵盤上的Enter鍵時,將執行一些操作。
參數: 螢幕專案(輸入控制項)
輸出: N/A
範例代碼:
當使用者在文字框中輸入內容並按下Enter鍵時,將顯示您輸入的文字。
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_ChangeableInputControl_onInputChanged\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><statement name=\"HANDLER\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createOutput</field></block></value><value name=\"content\"><block type=\"Control_ChangeableInputControl_getInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>inputControl</variable><variable>createOutput</variable><variable>youWrote</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">inputControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextInput\"><field name=\"type\">TextInputType.Text</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createOutput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"variables_set\"><field name=\"VAR\">youWrote</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">You wrote:</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">youWrote</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createOutput</field></block></value><next><block type=\"Control_ChangeableInputControl_onInputChanged\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><statement name=\"HANDLER\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createOutput</field></block></value><value name=\"content\"><block type=\"Control_ChangeableInputControl_getInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
當不輸入任何內容時,輸出:

當輸入內容並且使用者按下Enter鍵時,輸出:

設置初始值
輸入控制設定值
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_ChangeableInputControl_setInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"v\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow></value></block></xml>"}
此塊用於設置變數中的某些文本以供顯示。
參數:
- 螢幕專案(輸入控制項)
- 顯示設置:字串
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>inputControl</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">inputControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextArea\"/></value><next><block type=\"Control_ChangeableInputControl_setInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"v\"><shadow type=\"text\"><field name=\"TEXT\">Here is setting value</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
輸出:

顯示文字區域值
輸入控制件獲取值
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_ChangeableInputControl_getInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></xml>"}
此塊用於從文本區域獲取值以進行顯示。
參數: 螢幕專案(輸入控制項)
輸出: 屏幕專案
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>inputControl</variable><variable>valueInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">inputControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextArea\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">valueInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextInput\"><field name=\"type\">TextInputType.Text</field></block></value><next><block type=\"Control_ChangeableInputControl_setInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"v\"><shadow type=\"text\"><field name=\"TEXT\">Typing something~</field></shadow></value><next><block type=\"Control_ChangeableInputControl_setInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">valueInput</field></block></value><value name=\"v\"><block type=\"Control_ChangeableInputControl_getInputValue\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">valueInput</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
輸出:

將焦點設置在元素上
輸入控制焦點
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_InputControl_focus\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></xml>"}
此塊將焦點設置在文字區域。 如果它是聚焦的,您可以在文字區域中鍵入內容。
參數: 螢幕專案(輸入控制項)
輸出: N/A
範例代碼:
這裡設置按鈕來檢查變數是否被聚焦。
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><statement name=\"HANDLER\"><block type=\"Control_InputControl_focus\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>inputControl</variable><variable>createButton</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">inputControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextArea\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">createButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Click me to see focus</field></shadow></value></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><statement name=\"HANDLER\"><block type=\"Control_InputControl_focus\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value></block></statement><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
當它未聚焦時,輸出:

當按鍵檢視焦點時,輸出:

打字限制
輸入控制使能 false
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_InputControl_setInputEnabled\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"isEnabled\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></xml>"}
該塊限制使用者在文字區域中鍵入內容。
參數:
- 螢幕專案(輸入控制項)
- 顯示設定:布爾值 (True/False [Default])
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>inputControl</variable><variable>disableButton</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">inputControl</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextArea\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">disableButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Click me to see enable is true.</field></shadow></value></block></value><next><block type=\"Control_InputControl_setInputEnabled\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"isEnabled\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">disableButton</field></block></value><statement name=\"HANDLER\"><block type=\"Control_InputControl_setInputEnabled\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><value name=\"isEnabled\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></statement><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">inputControl</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">disableButton</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
當首先將啟用設置設置為 true 時,輸出:

點擊按鈕后,它將阻止文字區域,不允許您輸入,輸出:

選項清單
生成選項清單
創建選項清單
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></xml>"}
這個塊用於使用數位設置新的選項清單。
參數: 顯示設定:
- 布林值 (True/False [Default])
- 陣列
輸出: 屏幕專案
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
不帶選項的輸入:

帶有選項的輸出:

取消選擇所有選項
選項清單 取消選擇所有選項
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_deselectAll\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></xml>"}
這用於取消選擇選項清單中的所有選項。
參數: 螢幕專案(選項清單)
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable><variable>resultButton</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Show Result</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><statement name=\"HANDLER\"><block type=\"Control_OptionList_deselectAll\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
在單擊「顯示結果」按鈕之前,輸出:

按下按鈕後,輸出:

選擇所有選項
選項清單 選擇所有選項
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_selectAll\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></xml>"}
這用於取消選擇選項清單中的所有選項。
參數: 螢幕專案(選項清單)
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable><variable>resultButton</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Show Result</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><statement name=\"HANDLER\"><block type=\"Control_OptionList_selectAll\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
輸出:

點擊「顯示結果」按鈕後:

取消選擇某些選項
選項清單取消選擇選項陣列
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_deselectOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></xml>"}
這用於取消選擇相關選項。
參數:
- 螢幕專案(選項清單)
- 陣列
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable><variable>resultButton</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Show Result</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><statement name=\"HANDLER\"><block type=\"Control_OptionList_deselectOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"2\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
輸出:

點擊「顯示結果」按鈕後:

選擇一些選項
選項清單 選擇選項陣列
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_selectOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"2\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value></block></value></block></xml>"}
這用於選擇相關選項。
參數:
- 螢幕專案(選項清單)
- 陣列
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable><variable>resultButton</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Show Result</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><statement name=\"HANDLER\"><block type=\"Control_OptionList_selectOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"2\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
輸出:

點擊「顯示結果」按鈕後:

獲取選定的選項
選項清單 獲取選取選項
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_getSelectedOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></xml>"}
這用於獲取選定的選項。
參數: 螢幕專案(選項清單)
輸出: N/A
範例代碼:
使用 for 循環獲取所有選定的選項。
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">options</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_OptionList_getSelectedOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></value></block></statement></block></next></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable><variable>resultButton</variable><variable>options</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">resultButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Show Result</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">resultButton</field></block></value><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">options</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_OptionList_getSelectedOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></value></block></statement></block></next></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
選擇 b、c 並按兩下「顯示結果」 按鈕時的輸出:

更改選項清單大小
選項清單集大小
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></xml>"}
這用於設置選項清單的顯示大小。
參數:
- 螢幕專案(選項清單)
- 條件:數字(預設值:0)
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"Control_OptionList_setSize\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"size\"><shadow type=\"math_number\"><field name=\"NUM\">2</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
輸出:

具有多項選擇的下拉清單
選項清單允許多項選擇
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_setMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></xml>"}
這用於允許它是否可以選擇多個選項。
參數:
- 螢幕專案(選項清單)
- 條件:布爾值 (True/False [Default])
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"Control_OptionList_setMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
設定為 false 時的輸出:

設定為 true 時輸出:

檢查選項清單是否多個
選項清單是多個
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_isMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></xml>"}
它用於檢查它是否是多個。
參數: 螢幕專案(選項清單)
輸出: 布林值 (True/False)
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable><variable>checkMultiple</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">checkMultiple</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">checkMultiple</field></block></value><next><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_OptionList_isMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkMultiple</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">It is multiple.</field></shadow></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">checkMultiple</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">It is not multiple.</field></shadow></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
當它設置為 false 時,輸出:

當它設置為 true 時,輸出:

在選項清單中設置多項選擇
選項清單 設置選項陣列
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_setOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></xml>"}
這用於設置選項清單中的選項。
參數: 螢幕專案(選項清單)
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"Control_OptionList_setOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
輸出:

獲取所有選項
選項清單獲取選項
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_OptionList_getOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></xml>"}
這用於獲取選項清單中的所有選項。
參數: 螢幕專案(選項清單)
輸出: 屏幕專案
範例代碼:
使用 for 循環獲取所有選項。
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>optionList</variable><variable>options</variable><variable>index</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">optionList</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createOptionList\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"2\" _input_init=\"true\"></mutation><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value><value name=\"options\"><block type=\"lists_create_with\"><mutation items=\"3\" horizontalafter=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">a</field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\">b</field></shadow></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\">c</field></shadow></value></block></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">options</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_OptionList_getOptions\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">optionList</field></block></value></block></value><next><block type=\"pxt_controls_for\"><value name=\"VAR\"><shadow type=\"variables_get_reporter\"><field name=\"VAR\">index</field></shadow></value><value name=\"TO\"><shadow type=\"math_whole_number\"><field name=\"NUM\">0</field></shadow><block type=\"math_arithmetic\"><field name=\"OP\">MINUS</field><value name=\"A\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value></block></value><value name=\"B\"><shadow type=\"math_number\"><field name=\"NUM\">1</field></shadow></value></block></value><statement name=\"DO\"><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><value name=\"text\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">options</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"variables_get\"><field name=\"VAR\">index</field></block></value></block></value></block></value></block></statement></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
輸出:

檔輸入
生成文件輸入
創建檔案輸入
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createFileInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"true\"></mutation><field name=\"fileTypeFilter\">FileInputTypeFilter.None</field><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value></block></xml>"}
此塊允許您上傳帶有變數的檔。
參數: 顯示設定:無(預設)/布爾值(真/假[Default])
輸出: 屏幕專案
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>createFileInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createFileInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createFileInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"true\"></mutation><field name=\"fileTypeFilter\">FileInputTypeFilter.None</field><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createFileInput</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
您可以設定使用者是否可以選擇多個檔案。

當未選擇任何檔案時,輸出:

當將多個選擇設置為 false 時,輸出:

當將多個選擇設置為 true 時,輸出:

獲取以前的檔
檔輸入獲取檔
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_FileInput_getFiles\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></xml>"}
此塊從先前選定的檔中獲取檔。
參數: 螢幕專案(輸入控制:檔案輸入)
輸出: 屏幕專案
範例代碼:
為了檢查這一點,它可以與文件和數位的塊結合使用。 它設置了一個按鈕來檢查它是否可以獲取檔。
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">gettingFile</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_FileInput_getFiles\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></value><next><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">result</field></block></value><value name=\"content\"><block type=\"File_FileContainer_getName\"><value name=\"this\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">gettingFile</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></value></block></value></block></next></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>fileInput</variable><variable>createButton</variable><variable>result</variable><variable>gettingFile</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">fileInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createFileInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"Control_FileInput_setMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Getting files</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">result</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">result</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">gettingFile</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_FileInput_getFiles\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></value><next><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">result</field></block></value><value name=\"content\"><block type=\"File_FileContainer_getName\"><value name=\"this\"><block type=\"lists_index_get\"><value name=\"LIST\"><block type=\"variables_get\"><field name=\"VAR\">gettingFile</field></block></value><value name=\"INDEX\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></value></block></value></block></next></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
選擇PNG檔並按兩下「獲取檔案」 時,輸出:

當取得檔案名並按兩下「獲取檔案」 時,輸出:

當在檔案內取得影像並按下「獲取檔案」 時,輸出:

當在檔案內取得影片並按兩下「獲取檔」 時,輸出:

當獲取檔案內的文字(接受的檔案類型:txt)並按兩下「獲取檔」時,輸出:

檔案格式限制
檔輸入過濾器檔類型
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_FileInput_setFileTypeFilter\"><field name=\"filter\">FileInputTypeFilter.None</field><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></xml>"}
此塊限制用戶選擇具有其檔類型的檔。
參數:
- 螢幕專案(輸入控制:檔案輸入)
- 顯示設置:無(預設)/圖像/視頻/音訊
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>fileInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">fileInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createFileInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"Control_FileInput_setFileTypeFilter\"><field name=\"filter\">FileInputTypeFilter.Audio</field><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
沒有限制選擇檔案後的輸出:

選擇只允許影像輸入的檔案(接受的檔案類型:JPEG、PNG 等)後的輸出:

選擇只允許影片輸入的檔案(接受的檔案類型:MP4、M4A 等)後的輸出:

選擇只允許音訊輸入的檔案(接受的檔案類型:MP3、WAV 等)後的輸出:

具有多項選擇的文件輸入
檔輸入允許多選
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_FileInput_setMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></xml>"}
此塊用於設置使用者是否可以選擇一個或多個檔。
參數:
- 螢幕專案(輸入控制:檔案輸入)
- 顯示設定:布爾值 (True/False [Default])
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>createFileInput</variable><variable>createButton</variable><variable>count</variable><variable>gettingFile</variable><variable>fileInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createFileInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createFileInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"true\"></mutation><field name=\"fileTypeFilter\">FileInputTypeFilter.None</field><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></value><next><block type=\"Control_FileInput_setMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createFileInput</field></block></value><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createFileInput</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Getting the total number of files</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">count</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">gettingFile</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_FileInput_getFiles\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createFileInput</field></block></value></block></value><next><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><value name=\"content\"><block type=\"text_join\"><mutation items=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">There are </field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">gettingFile</field></block></value></block></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\"> file(s).</field></shadow></value></block></value></block></next></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
點擊按鈕后,它將顯示檔總量的結果,當它設置為 false 時,輸出:

當設定為 true 時,輸出:

檢查檔輸入是否多個
檔輸入是多個
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_FileInput_isMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></xml>"}
此塊檢查檔的數量是否僅為一個或多個。
參數: 螢幕專案(輸入控制:檔案輸入)
輸出: 屏幕專案
範例代碼:
它將與不同的邏輯塊相結合,例如 if-else 條件塊。
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_FileInput_isMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><value name=\"content\"><block type=\"text_join\"><mutation items=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">There are </field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">gettingFile</field></block></value></block></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\"> file(s).</field></shadow></value></block></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Only one file is selected.</field></shadow></value></block></statement></block></xml>"}
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>fileInput</variable><variable>createButton</variable><variable>count</variable><variable>gettingFile</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">fileInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createFileInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"1\" _input_init=\"true\"></mutation><field name=\"fileTypeFilter\">FileInputTypeFilter.None</field><value name=\"isMultiple\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">FALSE</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">createButton</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createButton\"><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Check multiple files</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><next><block type=\"variables_set\"><field name=\"VAR\">count</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createTextBlock\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><next><block type=\"ScreenItem_ScreenItem_onClick\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">createButton</field></block></value><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">gettingFile</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_FileInput_getFiles\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></value><next><block type=\"controls_if\"><mutation else=\"1\"/><value name=\"IF0\"><shadow type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></shadow><block type=\"Control_FileInput_isMultiple\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">fileInput</field></block></value></block></value><statement name=\"DO0\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><value name=\"content\"><block type=\"text_join\"><mutation items=\"3\"/><value name=\"ADD0\"><shadow type=\"text\"><field name=\"TEXT\">There are </field></shadow></value><value name=\"ADD1\"><shadow type=\"text\"><field name=\"TEXT\"/></shadow><block type=\"lists_length\"><value name=\"VALUE\"><block type=\"variables_get\"><field name=\"VAR\">gettingFile</field></block></value></block></value><value name=\"ADD2\"><shadow type=\"text\"><field name=\"TEXT\"> file(s).</field></shadow></value></block></value></block></statement><statement name=\"ELSE\"><block type=\"Control_TextBlock_setContent\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">count</field></block></value><value name=\"content\"><shadow type=\"text\"><field name=\"TEXT\">Only one file is selected.</field></shadow></value></block></statement></block></next></block></statement></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
當存在多個檔案時,輸出:

當僅包含一個檔案時,輸出:

數值輸入
生成數值輸入
創建數值輸入
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_createNumericInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></xml>"}
此模組用於創建數位 (1,2,3…) 輸入。
參數: 顯示設定:
- 最小值:op(預設值:0)
- 最大值:數字(預設值:0)
- 步驟:數字(預設值:0)
輸出: 屏幕專案
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>numInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">numInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createNumericInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"3\" _input_init=\"true\"></mutation><value name=\"min\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value><value name=\"max\"><shadow type=\"math_number\"><field name=\"NUM\">100</field></shadow></value><value name=\"step\"><shadow type=\"math_number\"><field name=\"NUM\">3</field></shadow></value></block></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">numInput</field></block></value></block></next></block></next></block></next></block></statement></block></xml>"}
輸入:

您可以使用鍵入或捲動來輸入值:

您可以設置最小值和最大值以及步長。 該步長表示如果將步長設置為 3,則只能輸入 3 的倍數,例如 3、6、9。

數值輸入中的步驟屬性
數值輸入設置步驟
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_NumericInput_setStep\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value><value name=\"step\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
此模組用於設置數位輸入的步長。
參數: 顯示設定:數字(預設:0)
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>numericInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">numericInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createNumericInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"Control_NumericInput_setStep\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value><value name=\"step\"><shadow type=\"math_number\"><field name=\"NUM\">2</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
當步長設定為 2 時,輸出:

數值輸入中的最大值限制
數值輸入集最大值
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_NumericInput_setMax\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value><value name=\"max\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
此模組用於設置數值輸入的最大值。
參數: 顯示設定:數字(預設:0)
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>numericInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">numericInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createNumericInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"Control_NumericInput_setMax\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value><value name=\"max\"><shadow type=\"math_number\"><field name=\"NUM\">5</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
當它設定為 5 時,它不能選擇大於 5 的值,輸出:

數值中的最小值限制
數值輸入設置最小值
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"Control_NumericInput_setMin\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value><value name=\"min\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}
此模組用於設置數值輸入的最小值。
參數: 顯示設定:數字(預設:0)
輸出: N/A
範例代碼:
{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>mainLayout</variable><variable>mainScreen</variable><variable>numericInput</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"variables_set\"><field name=\"VAR\">mainLayout</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"ScreenItem_createLayout\"/></value><next><block type=\"variables_set\"><field name=\"VAR\">mainScreen</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Screen_create\"><value name=\"label\"><shadow type=\"text\"><field name=\"TEXT\">Main</field></shadow></value><value name=\"layout\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value></block></value><next><block type=\"variables_set\"><field name=\"VAR\">numericInput</field><value name=\"VALUE\"><shadow type=\"math_number\"><field name=\"NUM\">0</field></shadow><block type=\"Control_createNumericInput\"><mutation xmlns=\"http://www.w3.org/1999/xhtml\" _expanded=\"0\" _input_init=\"false\"></mutation></block></value><next><block type=\"Control_NumericInput_setMin\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value><value name=\"min\"><shadow type=\"math_number\"><field name=\"NUM\">-1</field></shadow></value><next><block type=\"ScreenItem_Layout_add\"><value name=\"this\"><block type=\"variables_get\"><field name=\"VAR\">mainLayout</field></block></value><value name=\"item\"><block type=\"variables_get\"><field name=\"VAR\">numericInput</field></block></value></block></next></block></next></block></next></block></next></block></statement></block></xml>"}
當它設定為 -1 時,它不能選擇小於 -1 的值,輸出:

目録