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

#1 2011-04-18 15:22:43

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Spliting Strings

Okay so I am making a programming language in Scratch. I need to know how i could split a string. For instance, if someone wanted to print text they could write:

Code:

SAY "Hello"

If possible, I would like it to just print Hello to the Output list. Is this possible?

Offline

 

#2 2011-04-18 15:44:23

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Spliting Strings

ProgrammingFreak wrote:

Okay so I am making a programming language in Scratch. I need to know how i could split a string. For instance, if someone wanted to print text they could write:

Code:

SAY "Hello"

If possible, I would like it to just print Hello to the Output list. Is this possible?

Yes, it just requires a lot of repeats, if elses, joins, letter (), and length ofs. When I gave it a try, I used a symbol (e.g. /s) to signify that the command was a say command. I would post an example, but I'm a bit busy search my hard drive for some sprites I've lost.  tongue


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#3 2011-04-18 15:53:29

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Spliting Strings

markyparky56 wrote:

ProgrammingFreak wrote:

Okay so I am making a programming language in Scratch. I need to know how i could split a string. For instance, if someone wanted to print text they could write:

Code:

SAY "Hello"

If possible, I would like it to just print Hello to the Output list. Is this possible?

Yes, it just requires a lot of repeats, if elses, joins, letter (), and length ofs. When I gave it a try, I used a symbol (e.g. /s) to signify that the command was a say command. I would post an example, but I'm a bit busy search my hard drive for some sprites I've lost.  tongue

OKay, so like:

Code:

/s 'hello'

Offline

 

#4 2011-04-18 15:57:07

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Spliting Strings

ProgrammingFreak wrote:

markyparky56 wrote:

ProgrammingFreak wrote:

Okay so I am making a programming language in Scratch. I need to know how i could split a string. For instance, if someone wanted to print text they could write:

Code:

SAY "Hello"

If possible, I would like it to just print Hello to the Output list. Is this possible?

Yes, it just requires a lot of repeats, if elses, joins, letter (), and length ofs. When I gave it a try, I used a symbol (e.g. /s) to signify that the command was a say command. I would post an example, but I'm a bit busy search my hard drive for some sprites I've lost.  tongue

OKay, so like:

Code:

/s 'hello'

You don't even really have to put the speech marks, unless you add compatibility with variables, and stuff.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#5 2011-04-18 15:59:52

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Spliting Strings

Look at my latest project it does just this!
EDIT:
Link here

Last edited by johnnydean1 (2011-04-18 16:00:39)


You can now reach me on Twitter @johnnydean1_

Offline

 

#6 2011-04-18 16:05:21

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Spliting Strings

johnnydean1 wrote:

Look at my latest project it does just this!
EDIT:
Link here

big_smile  Cool!

Offline

 

#7 2011-04-18 16:08:35

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Spliting Strings

Need anything else?


You can now reach me on Twitter @johnnydean1_

Offline

 

#8 2011-04-18 16:09:03

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Spliting Strings

johnnydean1 wrote:

Need anything else?

Would you like to help work on it?  big_smile

Offline

 

#9 2011-04-18 16:10:26

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Spliting Strings

ProgrammingFreak wrote:

johnnydean1 wrote:

Need anything else?

Would you like to help work on it?  big_smile

I can help. You can post on that project with anything you need.


You can now reach me on Twitter @johnnydean1_

Offline

 

#10 2011-04-18 16:11:47

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Spliting Strings

johnnydean1 wrote:

ProgrammingFreak wrote:

johnnydean1 wrote:

Need anything else?

Would you like to help work on it?  big_smile

I can help. You can post on that project with anything you need.

Okay. Lemme upload a new version that I can add a few things and then we can talk.

Offline

 

#11 2011-04-18 16:26:02

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Spliting Strings

Um, I'd like to use your code. Is that all right? Well at least guide me to the part of the splitting part. Should I just copy all your code into mine? Or put what I have onto yours?
the first will take forever....  hmm

Offline

 

#12 2011-04-18 16:28:33

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Spliting Strings

You can copy anything you want  smile


You can now reach me on Twitter @johnnydean1_

Offline

 

#13 2011-04-18 16:33:36

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Spliting Strings

johnnydean1 wrote:

You can copy anything you want  smile

Okay.  big_smile
*starts the long copying process*

I wish scratch had a better way.  hmm

Last edited by ProgrammingFreak (2011-04-18 16:34:06)

Offline

 

#14 2011-04-18 16:42:42

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Spliting Strings

ProgrammingFreak wrote:

johnnydean1 wrote:

You can copy anything you want  smile

Okay.  big_smile
*starts the long copying process*

I wish scratch had a better way.  hmm

Same


You can now reach me on Twitter @johnnydean1_

Offline

 

#15 2011-04-18 16:48:01

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Spliting Strings

ProgrammingFreak wrote:

johnnydean1 wrote:

You can copy anything you want  smile

Okay.  big_smile
*starts the long copying process*

I wish scratch had a better way.  hmm

Ever heard of export? You can copy what parts you want into a sprite, export it and import it into your own project.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#16 2011-04-18 16:48:32

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: Spliting Strings

markyparky56 wrote:

ProgrammingFreak wrote:

johnnydean1 wrote:

You can copy anything you want  smile

Okay.  big_smile
*starts the long copying process*

I wish scratch had a better way.  hmm

Ever heard of export? You can copy what parts you want into a sprite, export it and import it into your own project.

OH lol. I've never used it for the code before.  tongue

Offline

 

#17 2011-04-18 16:53:56

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Spliting Strings

ProgrammingFreak wrote:

markyparky56 wrote:

ProgrammingFreak wrote:


Okay.  big_smile
*starts the long copying process*

I wish scratch had a better way.  hmm

Ever heard of export? You can copy what parts you want into a sprite, export it and import it into your own project.

OH lol. I've never used it for the code before.  tongue

tongue  From what I can see, all the code for JD1's project is in one sprite, so all you need to do it export said sprite. It is, in essence, an interpreter at the simplest. Nice work Jd1.  smile  Though, I've noticed that in the Experimental viewer, it doesn't loop like in the player.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#18 2011-04-18 16:56:19

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Spliting Strings

markyparky56 wrote:

Nice work Jd1.  smile  Though, I've noticed that in the Experimental viewer, it doesn't loop like in the player.

Why thank you.

And the experimental viewer must be a bug...


You can now reach me on Twitter @johnnydean1_

Offline

 

#19 2011-04-18 17:00:19

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Spliting Strings

johnnydean1 wrote:

markyparky56 wrote:

Nice work Jd1.  smile  Though, I've noticed that in the Experimental viewer, it doesn't loop like in the player.

Why thank you.

And the experimental viewer must be a bug...

It is afterall, experimental.


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#20 2011-04-18 17:20:34

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Spliting Strings

markyparky56 wrote:

johnnydean1 wrote:

markyparky56 wrote:

Nice work Jd1.  smile  Though, I've noticed that in the Experimental viewer, it doesn't loop like in the player.

Why thank you.

And the experimental viewer must be a bug...

It is afterall, experimental.

Well yes...



@Everyone
I am working on a new way of doing this. I don't think it will be faster but it should be better at detecting and able to use spaces.
EDIT:
Done see my latest project. It doesn't work in flash player (v23) as <0= > (0=nothing).

Last edited by johnnydean1 (2011-04-19 03:30:30)


You can now reach me on Twitter @johnnydean1_

Offline

 

#21 2011-04-19 10:48:35

logiblocs
Scratcher
Registered: 2010-05-05
Posts: 100+

Re: Spliting Strings

try this idea:
http://i55.tinypic.com/95wfu8.gif

I had to do the same thing so I came up with this idea. the cmd is original, cmdname would be the SAY bit and cmdargs would be the 'Hello World' bit.

--EDIT--
where the bit says nothing or nothing one of them is a space and the other nothing.

Last edited by logiblocs (2011-04-19 10:50:48)

Offline

 

#22 2011-04-19 18:07:51

ScratchReallyROCKS
Scratcher
Registered: 2009-04-22
Posts: 1000+

Re: Spliting Strings

Splitting strings for a programming language gets annoying after a while. I usually have a script load all the characters into a list, then loop through the list until it finds the character to split at, then load both or all strings into variables or a list.


http://imageshack.us/a/img694/3806/sigmad.png

Offline

 

#23 2011-04-20 00:38:35

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Spliting Strings

You could use the method I use in QuickSilver.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#24 2011-04-20 04:32:31

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Spliting Strings

Why again?
You can use a command entrance char (i use <) and a command exit char (>) and use the arguments in a list like:
<say> hello; 2
would say hello for 2 secs.
big_smile


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#25 2011-04-20 04:40:06

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Spliting Strings

That sounds like a good idea, bbbeb.

Offline

 

Board footer