m (→‎Offline decimal trick: Fixed a block.)
m
Line 9: Line 9:
 
}}
 
}}
 
The '''Join ()()''' [[Blocks|block]] is an [[Operators Blocks|Operators block]] and a [[Reporter Block|Reporter block]]. 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.
 
The '''Join ()()''' [[Blocks|block]] is an [[Operators Blocks|Operators block]] and a [[Reporter Block|Reporter block]]. 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.
 
==Workaround==
 
{{main|List of Block Workarounds}}
 
This block can be replicated with the following code:
 
 
<scratchblocks>
 
set [count v] to [0]
 
repeat (length of (insert1))
 
change [count v] by (1)
 
add (letter (count) of (instert1)) to [final v]
 
end
 
set [count v] to [0]
 
repeat (length of (insert2))
 
change [count v] by (1)
 
add (letter (count) of (insert2)) to [final v]
 
end
 
set [result v] to (final)
 
</scratchblocks>
 
 
The [[variable]] "result" contains the result.
 
  
 
==Example Uses==
 
==Example Uses==
If words, numbers, sentences {{-}} any two values {{-}} must be concatencated together, this block easily does the job.
+
If words, numbers, sentences{{-}}any two values{{-}}must be concatenated together, this block easily does the job.
  
Some common uses for the '''Join ()()''' block:
+
Some common uses for the Join ()() block:
 
*Joining words and variables to create a sentence
 
*Joining words and variables to create a sentence
  
Line 52: Line 32:
 
{{Note|This does not work on numbers that are already negative.}}
 
{{Note|This does not work on numbers that are already negative.}}
  
==Offline decimal trick==
+
===Offline decimal trick===
Offline, numbers in variables and speech bubbles usually round to only one decimal place. In some [[projects]], 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.
+
Offline, numbers in variables and speech bubbles usually round to only one decimal place. In some [[projects]], 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:
 
*The original script:
 +
 
<scratchblocks>
 
<scratchblocks>
 
set [number v] to ([sqrt v] of ((item (1 v) of [list v]) * (3)))
 
set [number v] to ([sqrt v] of ((item (1 v) of [list v]) * (3)))
 
</scratchblocks>
 
</scratchblocks>
 +
 
*Script with more decimals:
 
*Script with more decimals:
 +
 
<scratchblocks>
 
<scratchblocks>
 
set [number v] to (join([sqrt v] of ((item (1 v) of [list v]) * (3))) [])
 
set [number v] to (join([sqrt v] of ((item (1 v) of [list v]) * (3))) [])
 
</scratchblocks>
 
</scratchblocks>
 +
 
*To set the number of decimal places, use a script like this:
 
*To set the number of decimal places, use a script like this:
 +
 
<scratchblocks>
 
<scratchblocks>
 
set [number v] to (join((round (([10^] of (decimal places)) * ([sqrt v] of ((item (1 v) of [list v]) * (3))))) / ([10^ v] of (decimal places)))[])
 
set [number v] to (join((round (([10^] of (decimal places)) * ([sqrt v] of ((item (1 v) of [list v]) * (3))))) / ([10^ v] of (decimal places)))[])
 
</scratchblocks>
 
</scratchblocks>
<!-- <scratchblocks>set [number v] to (join ((round (([10^ v] of (decimal places)) * ([sqrt v] of ((item (1) of [list v]) * (3))))) / ([10^ v] of (decimal places))) [])</scratchblocks> -->
+
 
 +
==Workaround==
 +
{{main|List of Block Workarounds}}
 +
This block can be replicated with the following code:
 +
 
 +
<scratchblocks>
 +
set [count v] to [0]
 +
repeat (length of (insert1))
 +
change [count v] by (1)
 +
add (letter (count) of (instert1)) to [final v]
 +
end
 +
set [count v] to [0]
 +
repeat (length of (insert2))
 +
change [count v] by (1)
 +
add (letter (count) of (insert2)) to [final v]
 +
end
 +
set [result v] to (final)
 +
</scratchblocks>
 +
 
 +
The [[variable]] "result" contains the result.
 +
 
 
{{Operators Blocks}}
 
{{Operators Blocks}}
 
[[Category:Operators Blocks]]
 
[[Category:Operators Blocks]]
 
[[de:Verbinde () () (Block)]]
 
[[de:Verbinde () () (Block)]]

Revision as of 04:56, 12 October 2013

Join ()()
2.0 Join ()().png
Category Operators
Type Reporter
Introduced in 1.4

The Join ()() block is an Operators block and a Reporter block. 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.

Example Uses

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
when flag clicked
ask [What's your name?] and wait
say (join (join (join (join [Hello ] (answer))[. My name is ]) (Person's name)) [.])
  • Place a variable in a message (eg. "You completed 2 loops")
say (join [The score is ] (join (score) [.]))
  • An easy method of negating a positive number
set [variable v] to (join [-] (number))
Note 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 projects, 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:
set [number v] to ([sqrt v] of ((item (1 v) of [list v]) * (3)))
  • Script with more decimals:
set [number v] to (join([sqrt v] of ((item (1 v) of [list v]) * (3))) [])
  • To set the number of decimal places, use a script like this:
set [number v] to (join((round (([10^] of (decimal places)) * ([sqrt v] of ((item (1 v) of [list v]) * (3))))) / ([10^ v] of (decimal places)))[])

Workaround

Main article: List of Block Workarounds

This block can be replicated with the following code:

set [count v] to [0]
repeat (length of (insert1))
change [count v] by (1)
add (letter (count) of (instert1)) to [final v]
end
set [count v] to [0]
repeat (length of (insert2))
change [count v] by (1)
add (letter (count) of (insert2)) to [final v]
end
set [result v] to (final)

The variable "result" contains the result.

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