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

#1 2007-05-20 08:07:41

jsimone
Scratcher
Registered: 2007-05-20
Posts: 28

String concatenation, is there a way?

Hey all,

Congrats to the Scratch team for this excellent work.   Just got on the bandwagon this week and my kids are delighted.  My 11 year old has cranked out 3 projects already.

I have a question about string concatenation and string methods in general.  While I realize this is not Java ... is it possible to concat 2 strings?

For example I want to create a simple math practice game for kids like this ...

set num1 = rand(1 to 10)
set num2 = rand(1 to 10)
set result = num1 * num2
say "what is" num1 X num2 ?

I would then collect the result (one or more digits) and then manipulate the sprite depending on whether correct or not.

I don't see a way to concat the numbers with the "What is" or with each other in the say block.

Also, it would be nice to be able to do a substring, leftmost and rightmost characters given the ability to do concat.

Offline

 

#2 2007-05-20 11:43:40

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: String concatenation, is there a way?

I'd love to have string values for variables and string concatenation, but they aren't there.

You can try
    1) saying things one after another
    2) using multiple sprites to say things (probably the easiest for your problem)
    3) printing the numbers on the background.  See my print_number and print_decimal scripts:

http://scratch.mit.edu/projects/kevin_karplus/2163
http://scratch.mit.edu/projects/kevin_karplus/2951

Offline

 

#3 2007-05-20 20:29:04

jsimone
Scratcher
Registered: 2007-05-20
Posts: 28

Re: String concatenation, is there a way?

Kevin,
Thanks for the pointers to your code.  In Scatch simple things should be simple, but in some cases, with missing constructs, simple things become difficult to implement.
Joe

Offline

 

#4 2007-06-01 01:09:03

rivendell
Scratcher
Registered: 2007-05-29
Posts: 24

Re: String concatenation, is there a way?

Perhaps this belongs in its own thread, but in general text-based input and output is not well supported in scratch.  As you've noted, "output" of variables using the "say" block is very limited.  Input is also very limited with just the "key X pressed" sensor.  There is no equivalent to the basic "input" statement, where the program will pause and then return a string.  Of course, then some string operators (at the very least == and != ) would help as well.

Offline

 

#5 2007-06-01 08:02:20

weissjd
Scratcher
Registered: 2007-05-16
Posts: 64

Re: String concatenation, is there a way?

I agree that string concatenation is a major missing feature, but like many of Scratch's limitations it can be solved with some creativity. This project is a great example of working around those limitations. Not only did the author get results he wanted, but in the process of working around limitations he created a great looking game by having characters say the numbers. It's not fully functional yet, but it might give you some good ideas: http://scratch.mit.edu/projects/UncleBits/8828

Offline

 

#6 2007-06-01 13:53:24

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: String concatenation, is there a way?

Number input and output (not using say) are handled in my RPN calculator and print_decimal programs:

http://scratch.mit.edu/projects/kevin_karplus/2164
http://scratch.mit.edu/projects/kevin_karplus/2951

Real string I/O would be harder, since Scartch has no string operators at all, just string constants for say and think.

Offline

 

#7 2007-06-01 15:23:08

jsimone
Scratcher
Registered: 2007-05-20
Posts: 28

Re: String concatenation, is there a way?

How about real string I/O for things like ...

  "Player 1, what is your name?"
Jimmy
...
  "Ok, Jimmy its your turn now."

Presently there is no way, it seems, to do this simple thing.

Offline

 

#8 2007-06-01 16:42:44

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: String concatenation, is there a way?

String variables and string I/O would be nice.
They're on my wish list, but *after* arrays.

Offline

 

#9 2007-06-01 17:44:51

LodiJoe
Scratcher
Registered: 2007-05-16
Posts: 4

Re: String concatenation, is there a way?

I agree with kevin that Scratch should have string variables and arrays, etc.  My program Word Play at:
http://scratch.mit.edu/projects/LodiJoe/9234
is very limited because I had to resort to key presses for input instead of  having string variables to teach high frequency words.

Offline

 

Board footer