From Test-Scratch-Wiki
字串组合 () 和 () | |
字串組合 [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))
![]() | 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.
() + ()
• () - () • () * () • () / () • 随机取数 () 到 () • () < () • () = () • () > () • () 且 () • () 或 () • () 不成立 • 字串组合 () 和 () • 字串中第 () 字 () • 字串长度 () • ) 除 () 的馀数 • 四舍五入数值 () • () 数值 ()更多积木… |