Join ()()
join ()()
Category Operators
Type Reporter
Introduced in 23Jan09 (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 "apple" and "banana" were put in the block, it would report "applebanana". To report "apple banana", use either "apple " and "banana" or "apple" and " banana", with a space.

To join three or more values together, drag copies of this block into its inputs.

join (join (join [] []) []) (join [] [])
Joining five strings
join [apple ] (join [banana ] [cherry])
Joining three strings

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 (e.g. "You completed 2 loops")
say (join [The score is ] (join (score) [.]))
  • An easy method of negating a positive number
set [variable v] to (join [-] (variable))
Note Note: This does not work on numbers that are already negative.
  • Using hex inputs in pen colors
set pen color to (join [0x] (hex input))

Showing more decimal places in speech bubbles

Results of calculations in speech bubbles are normally rounded to only two decimal places. 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 reports the number with more decimal places.

  • The original script:
say ([sqrt v] of ((item (1) of [list v]) * (3)))
  • Script with more decimals:
say (join([sqrt v] of ((item (1) of [list v]) * (3))) [])
  • To set the number of decimal places, use a script like this:
say (join((round (([10^ v] of (decimal places)::operators) * ([sqrt v] of ((item (1) of [list v]) * (3))))) / ([10^ v] of (decimal places)::operators))[])

Special Uses

Since sprite names and costume names are case sensitive, the

switch costume to (join (1) ())

block switches to the costume name "1", whereas the

switch costume to (round (1))

block switches to the first costume in the editor, which might be named "costume 1".
The join () () block is thus used often to switch costumes, since it always returns a string.

Workaround

Main article: List of Block Workarounds

This block can be replicated with the following code:

delete all of [final v]
set [count v] to [0]
repeat (length of (insert1))
change [count v] by (1)
add (letter (count) of (insert1)) 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. This works because list reporters join all of the items in a list without spaces if they are all 1 character long, and so by taking just 1 letter from each string at a time and putting them into the list, the reporter has the same result as the join block in most cases.

References


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