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

#726 2010-06-20 13:45:37

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: Cool custom blocks in Scratch

LS97 wrote:

@TheSuccessor:
i can try. should be easy.

I know. Should be a 'one line' function. Darned if I can find the smalltalk equivalent of javascripts' 'eval()' anywhere online though. That said, wish you luck.  smile
[Edited by fullmoon to remove mild expletive]

Last edited by fullmoon (2010-12-05 11:59:00)


/* No comment */

Offline

 

#727 2010-06-20 13:52:50

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Cool custom blocks in Scratch

TheSuccessor wrote:

LS97 wrote:

@TheSuccessor:
i can try. should be easy.

I know. Should be a 'one line' function. * if I can find the smalltalk equivalent of javascripts' 'eval()' anywhere online though. That said, wish you luck.  smile

Compiler evaluate: t1 with: self.

(that was from memory, don't yell at me if it's wrong)

EDIT: I mean

Code:

Compiler evaluate: t2 for: self logged: false

Last edited by nXIII (2010-06-20 13:53:54)


nXIII

Offline

 

#728 2010-06-20 16:09:24

paserra
Scratcher
Registered: 2010-06-06
Posts: 10

Re: Cool custom blocks in Scratch

paserra wrote:

Hi,
do someone knows how to implement a routine equivalent to strtok (in c) using squeak?
A similar scratch block cold be useful for parsing list items (loaded from a text file).
Regards,
Pier Andrea.

I've started to program in SmallTalk few days ago: this is my first try to make a block:
This is the block that returns a parsed string (It has 3 argument: 1) the string to tokenize; 2) the chars used as separators; 3) the number of the token to return as result. (a NULL value is returned as error or end-of-tokens).

('strtok %s %s %n' #r #str:tok:num: 'one,two,three' ',' 2)

str: t1 tok: t2 num: t3
    | mydata itemnum numX |
    mydata < t1 findTokens: t2.
    itemnum < mydata size.
    t3 < 1 | (t3 > itemnum)
        ifTrue: [numX < '']
        ifFalse: [numX < mydata at: t3].
    ^ numX

Sorry for the style, it seems to work. It could be useful for parsing CSV files in Panther. If someone is able to insert the parsed strings directly in a list object it could be great!
Regards,
Pier Andrea.

Offline

 

#729 2010-06-20 23:18:55

jmarie
Scratcher
Registered: 2010-03-13
Posts: 7

Re: Cool custom blocks in Scratch

hmmm?

Offline

 

#730 2010-06-21 07:37:40

Zorbak42
Scratcher
Registered: 2009-01-27
Posts: 100+

Re: Cool custom blocks in Scratch

LS97 wrote:

Zorbak42 wrote:

Anyone know if it's possible to convert a project made with a mod of Scratch into a .exe and have the mod's extra blocks work? (and if so, how?) I haven't tried, but I assume Jens' Scratch2Exe doesn't work on projects made with mods?

ok!
i'm back and ready to tell you!
take Jens' sratch2exe 'compiler' folder.
go to 'kit'.
this folder is similar to the scratch one, don't you agree?
rename runtime.image to runtime.backup
add you own image and rename it runtime.image
important! this image should be a COPY of the original, not dragged into the folder.
open that image in scratch.exe by dragging it onto it.
open the system browser in your program.
go to ui-panes, frameMorph, menu/button actions, quitScratch, and replace that code with

Code:

 quitScratch
    self closeMediaEditorsAndDialogs ifFalse: [^ self].
    self stopAll.
    Smalltalk snapshot: false andQuit: true

and click accept.
save the image, and try it on a project made with your mod!

I tried this with Panther and when I ran the .exe, it opened up an empty, default project. Also, when I pressed the back button in presentation mode, it just goes to the normal Panther window instead of closing it. I've noticed that most mods (including Panther) open an empty project when you try opening a project (by double-clicking the project, not by choosing File > Open...). Is this why it opens an empty project? And why does the back button not close it?

Offline

 

#731 2010-06-21 09:45:27

Billybob-Mario
Scratcher
Registered: 2008-01-05
Posts: 500+

Re: Cool custom blocks in Scratch

paserra wrote:

paserra wrote:

Hi,
do someone knows how to implement a routine equivalent to strtok (in c) using squeak?
A similar scratch block cold be useful for parsing list items (loaded from a text file).
Regards,
Pier Andrea.

I've started to program in SmallTalk few days ago: this is my first try to make a block:
This is the block that returns a parsed string (It has 3 argument: 1) the string to tokenize; 2) the chars used as separators; 3) the number of the token to return as result. (a NULL value is returned as error or end-of-tokens).

('strtok %s %s %n' #r #str:tok:num: 'one,two,three' ',' 2)

str: t1 tok: t2 num: t3
    | mydata itemnum numX |
    mydata < t1 findTokens: t2.
    itemnum < mydata size.
    t3 < 1 | (t3 > itemnum)
        ifTrue: [numX < '']
        ifFalse: [numX < mydata at: t3].
    ^ numX

Sorry for the style, it seems to work. It could be useful for parsing CSV files in Panther. If someone is able to insert the parsed strings directly in a list object it could be great!
Regards,
Pier Andrea.

What does it do?

Offline

 

#732 2010-06-21 12:24:15

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: Cool custom blocks in Scratch

nXIII wrote:

TheSuccessor wrote:

LS97 wrote:

@TheSuccessor:
i can try. should be easy.

I know. Should be a 'one line' function. * if I can find the smalltalk equivalent of javascripts' 'eval()' anywhere online though. That said, wish you luck.  smile

Compiler evaluate: t1 with: self.

(that was from memory, don't yell at me if it's wrong)

EDIT: I mean

Code:

Compiler evaluate: t2 for: self logged: false

Thanks nXIII.
By the way, you said at one point something was from memory. That sort of implies you were going to look it up. I'd be interested to see this information if it's online.

Last edited by TheSuccessor (2010-06-21 12:24:45)


/* No comment */

Offline

 

#733 2010-06-21 13:26:07

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

Zorbak42 wrote:

I tried this with Panther and when I ran the .exe, it opened up an empty, default project. Also, when I pressed the back button in presentation mode, it just goes to the normal Panther window instead of closing it. I've noticed that most mods (including Panther) open an empty project when you try opening a project (by double-clicking the project, not by choosing File > Open...). Is this why it opens an empty project? And why does the back button not close it?

yep. sorry. i found a glitch about why it doesnt close. the code i made you edit is to close without asking to save. in ScratchPresenterMorph you hve to change the exitButton's code to quitScratch instead of exitPresentation mode.

That was off my head, i could get it wrong  smile

Offline

 

#734 2010-06-21 19:44:58

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Cool custom blocks in Scratch

TheSuccessor wrote:

nXIII wrote:

TheSuccessor wrote:


I know. Should be a 'one line' function. * if I can find the smalltalk equivalent of javascripts' 'eval()' anywhere online though. That said, wish you luck.  smile

Compiler evaluate: t1 with: self.

(that was from memory, don't yell at me if it's wrong)

EDIT: I mean

Code:

Compiler evaluate: t2 for: self logged: false

Thanks nXIII.
By the way, you said at one point something was from memory. That sort of implies you were going to look it up. I'd be interested to see this information if it's online.

Ah... no, I just look around in the source code a bit; I knew where the method was, but not what the exact method was.


nXIII

Offline

 

#735 2010-06-21 20:38:20

Zorbak42
Scratcher
Registered: 2009-01-27
Posts: 100+

Re: Cool custom blocks in Scratch

LS97 wrote:

Zorbak42 wrote:

I tried this with Panther and when I ran the .exe, it opened up an empty, default project. Also, when I pressed the back button in presentation mode, it just goes to the normal Panther window instead of closing it. I've noticed that most mods (including Panther) open an empty project when you try opening a project (by double-clicking the project, not by choosing File > Open...). Is this why it opens an empty project? And why does the back button not close it?

yep. sorry. i found a glitch about why it doesnt close. the code i made you edit is to close without asking to save. in ScratchPresenterMorph you hve to change the exitButton's code to quitScratch instead of exitPresentation mode.

That was off my head, i could get it wrong  smile

smile  You got it right, it exit's Panther rather than just presentation mode, but it still doesn't open the project, just a blank, new one. Any ideas?

Offline

 

#736 2010-06-22 01:51:05

paserra
Scratcher
Registered: 2010-06-06
Posts: 10

Re: Cool custom blocks in Scratch

Billybob-Mario wrote:

paserra wrote:

paserra wrote:

Hi,
do someone knows how to implement a routine equivalent to strtok (in c) using squeak?
A similar scratch block cold be useful for parsing list items (loaded from a text file).
Regards,
Pier Andrea.

I've started to program in SmallTalk few days ago: this is my first try to make a block:
This is the block that returns a parsed string (It has 3 argument: 1) the string to tokenize; 2) the chars used as separators; 3) the number of the token to return as result. (a NULL value is returned as error or end-of-tokens).

('strtok %s %s %n' #r #str:tok:num: 'one,two,three' ',' 2)

str: t1 tok: t2 num: t3
    | mydata itemnum numX |
    mydata < t1 findTokens: t2.
    itemnum < mydata size.
    t3 < 1 | (t3 > itemnum)
        ifTrue: [numX < '']
        ifFalse: [numX < mydata at: t3].
    ^ numX

Sorry for the style, it seems to work. It could be useful for parsing CSV files in Panther. If someone is able to insert the parsed strings directly in a list object it could be great!
Regards,
Pier Andrea.

What does it do?

this is my last version of the block called "split". It splits a string in substrings using a separator ant puts the resulting strings in a list.

('split %s using %s in %L' #- #str:tok:num: '1,2,3' ',' 'list')

str: t1 tok: t2 num: t3
    | mydata value datasize count |
    mydata := t1 findTokens: t2.
    datasize := mydata size.
    count := 0.
    [count < datasize]
        whileTrue:
            [count := count + 1.
            value := mydata at: count.
            self append: value toList: t3]

Regards,
Pier Andrea.

Last edited by paserra (2010-06-22 01:52:20)

Offline

 

#737 2010-06-22 10:57:48

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

@Pier Andrea,

That's some nice code you have here! well done!

Offline

 

#738 2010-06-22 11:33:04

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

Re: Cool custom blocks in Scratch

Ive already done that...



Ask Panther if you dont belive me!


You can now reach me on Twitter @johnnydean1_

Offline

 

#739 2010-06-22 11:38:30

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: Cool custom blocks in Scratch

johnnydean1 wrote:

Ive already done that...



Ask Panther if you dont belive me!

No need to be like that about it. You both came up with it independently, and there's no need to brag about coming up with it first.


/* No comment */

Offline

 

#740 2010-06-22 11:45:01

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

Re: Cool custom blocks in Scratch

johnnydean1 wrote:

Ive already done that...



Ask Panther if you dont belive me!

What have you done?


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

 

#741 2010-06-22 14:09:48

paserra
Scratcher
Registered: 2010-06-06
Posts: 10

Re: Cool custom blocks in Scratch

LS97 wrote:

@Pier Andrea,

That's some nice code you have here! well done!

Thank you LS97, this is my first try. Now I can read text files and parsing strings.
I've tryed to insert the block split code in Panther and if I have a text file with text lines ending with CR (ascii= 13 or CRLF ascii= 13+10) , using the split block with the following arguments:
1) readfile block
2) newline char (or CRLF chars)
3) mylist
I can load the entire file directly in a list in one shot! It is great!
I hope this could be useful also for other users.
Regards.
Pier Andrea.

Offline

 

#742 2010-06-22 14:17:19

paserra
Scratcher
Registered: 2010-06-06
Posts: 10

Re: Cool custom blocks in Scratch

johnnydean1 wrote:

Ive already done that...



Ask Panther if you dont belive me!

Dear johnnydean1,
I asked help few post ago in this topic (see my previous messages #721 and #723) about my need to have a strtok block (called now split). I didn' found specific code in the forum nor received a response from Squeak developers. Than I've developed myself the code and posted here for everyone interested in it. Please, post me the link of your code I'm sure it is better than mine (I'm a c programmer, I've starting to program in Squeak 4 days ago).
Regards,
Pier Andrea.

Offline

 

#743 2010-06-22 15:07:07

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

Re: Cool custom blocks in Scratch

I dont have the code, youll have to ask Panther. Its called:
Decompile %s with %s as breaker

so....


BTW, yours is better!


You can now reach me on Twitter @johnnydean1_

Offline

 

#744 2010-06-22 17:19:28

paserra
Scratcher
Registered: 2010-06-06
Posts: 10

Re: Cool custom blocks in Scratch

Another small piece of code. This block is an analog of "join" block that merges two strings. The only difference is the variable number of arguments.

('concat %X' #r #concat:)

concat: t1
    | listlines myline merge count |
    listlines _ self lineCountOfList: t1.
    count _ 0.
    merge _ ''.
    [count < listlines]
        whileTrue:
            [count _ count + 1.
            myline _ self getLine: count ofList: t1.
            merge _ self concatenate: merge with: myline].
    ^ merge

Let me know what you think about.
Regards,
Pier Andrea.

p.s. the only limitation of the routine is the impossibility to include newline characters in the resulting string because of the use of list lines.

Last edited by paserra (2010-06-22 17:28:21)

Offline

 

#745 2010-06-22 19:19:09

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: Cool custom blocks in Scratch

LS97 wrote:

The 'showing?' block
This is an easy one. It gives a boolean response (True/False) of whether the sprite is showing or not.
Like before, copy this code into the 'looks' section of blockSpecs in ScratchSpriteMorph

Code:

('showing?' #b #getHidden)

then go to instance, 'looks ops' and replace the code in 'hide' with the code below (by the way, you're not deleting the hide block).

Code:

getHidden
    self isHidden = false ifTrue: [^ true].
    ^ false

Then right-click, clik accept and (maybe) type your initials. et voilà, you have your 'showing?' block up and ready.

It is easier to do this one using

Code:

('showing?' #b #isHidden)

. This means that you don't have to make a function, just add the block spec!


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#746 2010-06-22 19:31:05

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: Cool custom blocks in Scratch

billyedward wrote:

LS97 wrote:

The 'showing?' block
This is an easy one. It gives a boolean response (True/False) of whether the sprite is showing or not.
Like before, copy this code into the 'looks' section of blockSpecs in ScratchSpriteMorph

Code:

('showing?' #b #getHidden)

then go to instance, 'looks ops' and replace the code in 'hide' with the code below (by the way, you're not deleting the hide block).

Code:

getHidden
    self isHidden = false ifTrue: [^ true].
    ^ false

Then right-click, clik accept and (maybe) type your initials. et voilà, you have your 'showing?' block up and ready.

It is easier to do this one using

Code:

('showing?' #b #isHidden)

. This means that you don't have to make a function, just add the block spec!

OMG!!!!!!!!!! WHY WON'T YOU KEEP MAKING MORE VERSIONS OF STREAK!?!?!?!?


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#747 2010-06-23 07:41:54

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

billyedward wrote:

LS97 wrote:

The 'showing?' block
This is an easy one. It gives a boolean response (True/False) of whether the sprite is showing or not.
Like before, copy this code into the 'looks' section of blockSpecs in ScratchSpriteMorph

Code:

('showing?' #b #getHidden)

then go to instance, 'looks ops' and replace the code in 'hide' with the code below (by the way, you're not deleting the hide block).

Code:

getHidden
    self isHidden = false ifTrue: [^ true].
    ^ false

Then right-click, clik accept and (maybe) type your initials. et voilà, you have your 'showing?' block up and ready.

It is easier to do this one using

Code:

('showing?' #b #isHidden)

. This means that you don't have to make a function, just add the block spec!

no. if you would have actually looked at my code, you would have seen that isHidden reports if it's 'hidden?', not 'showing?'. so you have to make an instance for it to make life easier.

Offline

 

#748 2010-06-26 04:18:41

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

LS97 wrote:

nXIII wrote:

LS97 wrote:

@nXIII:
thanks!

although, i have one more question. how do you make the nested blocks repeat until a boolean comes true?

That's an already-defined special-form, I believe #doWhile, maybe?

hmm... i suppose so.
i'll play around with those forms.

nXIII,
back to page 24 in this thread.

you once told me that the function for the 'When %b is true' block was stored in a special form called doWhile. When i became i little better at squeak, i saw that in fact that's simply for a c block called 'do while %b', which was later replaced by the 'do until %b'.

it's exactly the same thing, but one of them waits until the condition is true, and one until the condition is false. Any other help?

PS. about the special forms for C blocks. How do you take the first argument for the block from the array it's stored into?

Offline

 

#749 2010-06-26 05:36:46

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

*bump*
please look at post 749

Offline

 

#750 2010-06-26 06:47:33

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Cool custom blocks in Scratch

BUMP! look at post 749!

Offline

 

Board footer