This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-02-13 18:16:18

vbconz
New Scratcher
Registered: 2013-02-13
Posts: 2

Concatenate strings - aka joining text and variables together

I'm new to scratch, but old to programming.

Was writing a demo prog with the kids. Really simple.

Cat (sprite 1) says, Hi What is your name? and gets an answer.
answer is pout into variable called yourname
Cat wants to say "Hello " <yourname>.

I checked on the forums, couldn't find any way of going
Say "Hello" + yourname.

Saw lots of people saying it is not easy. Here is my question nad an idea.

1 - Is there a way of doing this yet or is it still not possible to concatenate strings in a Say block?

2 - If answer one above is no - here is my tip.

when gf clicked
   ask "what is your name?" and wait
   Set <yourname> to  <answer>
   Say Join "Hello " + <yourname>
Join allows real time concatenation of strings and using them.

Offline

 

#2 2013-02-13 18:28:21

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: Concatenate strings - aka joining text and variables together

There's already a block for that, since 1.4 c: It's the "join" block (just as you said), under "Operators":

say (join [Hello, ](join (name)[!]))


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#3 2013-02-13 18:31:14

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Concatenate strings - aka joining text and variables together

vbconz wrote:

I'm new to scratch, but old to programming.

Was writing a demo prog with the kids. Really simple.

Cat (sprite 1) says, Hi What is your name? and gets an answer.
answer is pout into variable called yourname
Cat wants to say "Hello " <yourname>.

I checked on the forums, couldn't find any way of going
Say "Hello" + yourname.

Saw lots of people saying it is not easy. Here is my question nad an idea.

1 - Is there a way of doing this yet or is it still not possible to concatenate strings in a Say block?

2 - If answer one above is no - here is my tip.

when gf clicked
   ask [what is your name?] and wait
   Set [yourname v] to  (answer)
   Say (Join [Hello ] (yourname)>
Join allows real time concatenation of strings and using them.

Well, yes, there is a way to connect text and a variable together; in fact, you're already using it in your tip! It's the (join [] []) block! In fact, you can even use multiple join blocks inside of join blocks. For example:

when gf clicked
say (join (join [Hello! It's nice to meet you, Mr.] (Answer)) [! I earlier heard that you became a millionaire. Is that correct?])

I hope that this helps!


http://i46.tinypic.com/35ismmc.png

Offline

 

Board footer