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

#1 2011-06-17 17:09:23

Mozaz
Scratcher
Registered: 2009-05-19
Posts: 500+

Splitting a list item into parts, seperated by a comma

Hey there!

Say you have a list, and one of items has a piece of code similar to this:

Ember,Fire,10

(Hopefully most of you would have realised that this is indeed a move on pokemon where ember is the move, fire is the type and 10 is the damage)

Now I want to split the item into different variables called Move, Type and Damage. Splitting it is quite simple but I was wondering if there is a way to put each into individual variables.

I have tried something similar to taking each letter of the item and adding it onto a variable, and then adding on the next letter, however this doesn't seem to work..

Any ideas would be really helpful!

Thanks  smile


http://i33.tinypic.com/15i5fmp.png

Offline

 

#2 2011-06-17 17:19:48

Kileymeister_test
Scratcher
Registered: 2010-01-31
Posts: 100+

Re: Splitting a list item into parts, seperated by a comma

You can use a processor like this:
http://i53.tinypic.com/1193yxg.gif
Keep in mind it's not instantaneous, but it's quick.  (Maybe 15 frames maximum)

Explanation:
First this script breaks your string into individual letters, then compiles the letters together again until it reaches a comma.  It splices the letters already compiled together into the first word, skips over the comma, then starts compiling the letters in the next word.  It repeats this until the entire thing is separated.

P.S.  Wherever it says "Set WordProcess to ' '"  don't put a space in there, just delete the zero and leave it empty like that.
P.P.S.  Those answer blocks are just so you can test the script out, afterwards you can delete the top block and replace "answer" with the item of the list you are breaking up.

Last edited by Kileymeister_test (2011-06-17 17:27:42)


Kileymeister's test account.  I upload engines and demos and stuff for public use.
Currently Working on: Grapple Arms!

Offline

 

#3 2011-06-17 17:28:59

Mozaz
Scratcher
Registered: 2009-05-19
Posts: 500+

Re: Splitting a list item into parts, seperated by a comma

Kileymeister_test wrote:

You can use a processor like this:
http://i53.tinypic.com/1193yxg.gif
Keep in mind it's not instantaneous, but it's quick.  (Maybe 15 frames maximum)

Explanation:
First this script breaks your string into individual letters, then compiles the letters together again until it reaches a comma.  It splices the letters already compiled together into the first word, skips over the comma, then starts compiling the letters in the next word.  It repeats this until the entire thing is separated.

P.S.  Wherever it says "Set WordProcess to ' '"  don't put a space in there, just delete the zero and leave it empty like that.
P.P.S.  Those answer blocks are just so you can test the script out, afterwards you can delete the top block and replace "answer" with the item of the list you are breaking up.

Ah excellent! I completely forgot about the "join" block! Thanks for the quick response!


http://i33.tinypic.com/15i5fmp.png

Offline

 

Board footer