From Test-Scratch-Wiki

Translate: - English - 中文 
字串組合 () 和 ()
字串組合 [Hello ] 和 [World]
類別 運算類積木
形狀 橢圓形積木
加入於 1.4

The Join ()() 積木 is an 運算類積木 and a 橢圓形積木. The block concatenates, or "links" the two values together and reports the result — for example, if "hello" and "world" were put in the block, it would report "helloworld". To report "hello world", use either "hello " and "world" or "hello" and " world", with a space.

用法示例

If words, numbers, sentences—any two values—must be concatenated together, this block easily does the job.

Some common uses for the Join ()() block:

  • Joining words and variables to create a sentence
當 @greenflag 被點擊
詢問 [What's your name?] 並等待
說出 (字串組合 (字串組合 (字串組合 (字串組合 [Hello ] 和 (詢問的答案)) 和 [. My name is ]) 和 (Person's name)) 和 [.])
  • Place a 變量 in a message (e.g. "You completed 2 loops")
說出 (字串組合 [The score is ] 和 (字串組合 (score) 和 [.]))
  • An easy method of negating a positive number
變數 [variable v] 設為 (字串組合 [-] 和 (number))
Warning Note: This does not work on numbers that are already negative.

Offline decimal trick

Offline, numbers in variables and speech bubbles usually round to only one decimal place. In some 專案, it is necessary to have more. Placing the calculation in one input of the Join ()() block and leaving the other input empty "magically" reports the number with more decimal places.

  • The original script:
變數 [number v] 設為 ([sqrt v] 數值 ((清單第 (1 v) 項項目\( [list v] \) :: list) * (3)))
  • Script with more decimals:
變數 [number v] 設為 (字串組合 ([sqrt v] 數值 ((清單第 (1 v) 項項目\( [list v] \) :: list) * (3))) 和 [])
  • To set the number of decimal places, use a script like this:
變數 [number v] 設為 (字串組合 ((四捨五入數值 (([10^ v] 數值 (decimal places)) * ([sqrt v] 數值 ((清單第 (1 v) 項項目\( [list v] \) :: list) * (3))))) / ([10^ v] 數值 (decimal places))) 和 [])

應用

Main article: List of Block Workarounds

This block can be replicated with the following code:

變數 [count v] 設為 [0]
重複 (字串長度\( (insert1) \)) 次 
  變數 [count v] 改變 (1)
  新增項目 (字串中第 (count) 字\( (instert1) \)) \( [final v] \)
end
變數 [count v] 設為 [0]
重複 (字串長度\( (insert2) \)) 次 
  變數 [count v] 改變 (1)
  新增項目 (字串中第 (count) 字\( (insert2) \)) \( [final v] \)
end
變數 [result v] 設為 (final :: list)

The 變量 "result" contains the result.