From Test-Scratch-Wiki

询问 () 并等待
詢問 [What's your name?] 並等待
类别 侦测类积木
形狀 条形积木
加入於 1.4
The Scratch 喵咪 asking a question

The Ask () and Wait 积木 is a 侦测类积木 and a 条形积木. The block will make an input box (with the specified text above it) show at the bottom of the screen. Scratcher can input text into it and submit it, and the input is stored then in the 询问的答案 block. The Answer block automatically updates to most recent input.

This block and the 询问的答案 block appear obsolete in versions of Scratch under 1.4, because they were only introduced in 1.4.

用法示例

As this block allows users to input any text they want, it is widely used when a user must communicate with the 专案.

Some common uses for the Ask () and Wait block:

  • Chatbots

— receiving information from the user

詢問 [What's your name?] 並等待
說出 (字串組合 [Hello, ] 和 (字串組合 (詢問的答案) 和 [.]))
  • Setting preferences

— coordinates, color, and so on

詢問 [Color?] 並等待
效果 [顏色 v] 設為 (詢問的答案)
  • Receiving input

— asking the user to give a command

詢問 [Move how many steps?] 並等待
移動 (詢問的答案) 點

应用

Main article: List of Block Workarounds

Sensing Method

This block can be somewhat replicated with the following code:

說出 (question)
刪除第 (全部 v) 項 \( [answer v] \)
變數 [count v] 設為 [0]
重複直到 <<碰到 [滑鼠游標 v] ?> 且 <滑鼠鍵被按下?>> 
  如果 <[a v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [A] 為第 (count) 項\( [answer v] \)
  end
  如果 <[b v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [B] 為第 (count) 項\( [answer v] \)
  end
  如果 <[c v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [C] 為第 (count) 項\( [answer v] \)
  end
  如果 <[d v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [D] 為第 (count) 項\( [answer v] \)
  end
  如果 <[e v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [E] 為第 (count) 項\( [answer v] \)
  end
  如果 <[f v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [F] 為第 (count) 項\( [answer v] \)
  end
  如果 <[g v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [G] 為第 (count) 項\( [answer v] \)
  end
  如果 <[h v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [H] 為第 (count) 項\( [answer v] \)
  end
  如果 <[i v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [I] 為第 (count) 項\( [answer v] \)
  end
  如果 <[j v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [j] 為第 (count) 項\( [answer v] \)
  end
  如果 <[k v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [K] 為第 (count) 項\( [answer v] \)
  end
  如果 <[l v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [L] 為第 (count) 項\( [answer v] \)
  end
  如果 <[m v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [M] 為第 (count) 項\( [answer v] \)
  end
  如果 <[n v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [N] 為第 (count) 項\( [answer v] \)
  end
  如果 <[o v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [O] 為第 (count) 項\( [answer v] \)
  end
  如果 <[p v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [P] 為第 (count) 項\( [answer v] \)
  end
  如果 <[q v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [Q] 為第 (count) 項\( [answer v] \)
  end
  如果 <[r v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [R] 為第 (count) 項\( [answer v] \)
  end
  如果 <[s v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [S] 為第 (count) 項\( [answer v] \)
  end
  如果 <[t v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [T] 為第 (count) 項\( [answer v] \)
  end
  如果 <[u v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [U] 為第 (count) 項\( [answer v] \)
  end
  如果 <[v v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [V] 為第 (count) 項\( [answer v] \)
  end
  如果 <[w v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [W] 為第 (count) 項\( [answer v] \)
  end
  如果 <[x v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [X] 為第 (count) 項\( [answer v] \)
  end
  如果 <[y v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [Y] 為第 (count) 項\( [answer v] \)
  end
  如果 <[z v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [Z] 為第 (count) 項\( [answer v] \)
  end
  如果 <[0 v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [0] 為第 (count) 項\( [answer v] \)
  end
  如果 <[1 v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [1] 為第 (count) 項\( [answer v] \)
  end
  如果 <[2 v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [2] 為第 (count) 項\( [answer v] \)
  end
  如果 <[3 v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [3] 為第 (count) 項\( [answer v] \)
  end
  如果 <[4 v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [4] 為第 (count) 項\( [answer v] \)
  end
  如果 <[5 v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [5] 為第 (count) 項\( [answer v] \)
  end
  如果 <[6 v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [6] 為第 (count) 項\( [answer v] \)
  end
  如果 <[7 v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [7] 為第 (count) 項\( [answer v] \)
  end
  如果 <[8 v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [8] 為第 (count) 項\( [answer v] \)
  end
  如果 <[9 v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [9] 為第 (count) 項\( [answer v] \)
  end
  如果 <[向右 v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
  end
  如果 <[向左 v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (-1)
  end
  如果 <[空白 v] 鍵被按下?> 那麼 
    變數 [count v] 改變 (1)
    添加 [] 為第 (count) 項\( [answer v] \)
  end
  等待 (0.001) 秒
end
說出 []


Note Note: This does not work perfectly. See this project for more information.

The 清单 "answer" will replace the 询问的答案积木.

Hat Block Method

Text input can be retrieved in correct order and speed by using this method.

當 [a v] 鍵被按下
新增項目 [a] \( [queue v] \)

當 [b v] 鍵被按下
新增項目 [b] \( [queue v] \)

當 [c v] 鍵被按下
新增項目 [c] \( [queue v] \)

//and so forth for each key

當 [向左 v] 鍵被按下
刪除第 (last v) 項 \( [queue v] \) //  backspace function

當 @greenflag 被點擊
刪除第 (全部 v) 項 \( [queue v] \)
等待直到 <[向右 v] 鍵被按下?> //  this will confirm the user is done inputting
變數 [clump v] 設為 [] //  blank
變數 [n v] 設為 [1]
重複 (清單 [queue v] 的項目數 :: list) 次 
  變數 [clump v] 設為 (字串組合 (clump) 和 (清單第 (n) 項項目\( [queue v] \) :: list))
  變數 [n v] 改變 (1)
end //  compile list into a single string

(clump) //  will be the answer

Cancellation

To cancel the text box that appears once this block is activated; one must use the 停止全部积木. The project can be continued as normal by using a When [Timer v] > () block.

An example of when one might want to cancel the text box is if an answer is not received in a certain amount of time, or if a cancel button is pressed.

A common method of cancellation:

when green flag clicked
set [variable v] to [0]

set [variable v] to [1]
reset timer
stop [all v] // As soon as this block is activated the text box will disappear, so place this where the text box should disappear
when [timer v] > (0.1)
if <(variable) = [0]> then
stop [this script v]
end
... // Continue here as normal

An example of this can be found here.

参见

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