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

#1 2010-08-25 09:04:16

rubiks_cube_guy238
Scratcher
Registered: 2009-07-02
Posts: 100+

How to make a working [when <> is true] block

Okay. Go to Scratch-Blocks->WhenHatBlockMorph and add two new methods in the instance side:

stepTime
^ 0.1

and

step
self evaluateCondition ifTrue: [self start]

Now add a new block in the ScriptableScratchMorph blockSpecs:

('' #W #-)

(We don't give the block a name because the WhenHatBlockMorph class automatically adds the label.)

Finally, go to ScriptableScratchMorph->blockFromTuple:receiver: and delete the text that says

(t6 isKindOf: WhenHatBlockMorph) ifTrue: [t6 color: Color red].

It's that easy!  tongue

BUG FIX: The block won't work if you switch to another sprite or switch to presentation mode. To fix this, go back to WhenHatBlockMorph and delete the #step and #stepTime methods. Now, go to ScriptableScratchMorph step:

step
    blocksBin
        submorphsDo: [:each | (each isKindOf: WhenHatBlockMorph)
                ifTrue: [each evaluateCondition ifTrue: [each start]]].
    costume mediaStep ifTrue: [self costumeChanged]

Credit to MathWizz for the bug fix.

FURTHER BUG FIX: This isn't exactly a bug fix, but it's simpler. Copy the following code:

Code:

!ScratchFrameMorph methodsFor: 'stepping'!
processWhenConditions
    | t1 |
    "true ifTrue: [^ self]."
    t1 _ workPane submorphs select: [:t2 | t2 isKindOf: ScriptableScratchMorph].
    t1 _ t1 copyWith: workPane.
    t1 do: [:t3 | t3 scripts do: [:t4 | (t4 isMemberOf: WhenHatBlockMorph)
                ifTrue: [(t4 hasRunningProcess not and: [t4 evaluateCondition])
                        ifTrue: [t4 start; layoutChanged]]]]! !

!ScratchPresenterMorph methodsFor: 'event handling'!
processWhenConditions
    | t1 |
    "true ifTrue: [^ self]."
    t1 _ stage submorphs select: [:t2 | t2 isKindOf: ScriptableScratchMorph].
    t1 _ t1 copyWith: stage.
    t1 do: [:t3 | t3 scripts do: [:t4 | (t4 isMemberOf: WhenHatBlockMorph)
                ifTrue: [(t4 hasRunningProcess not and: [t4 evaluateCondition])
                        ifTrue: [t4 start; layoutChanged]]]]! !

paste it in a workspace (you find the option on the open browser menu), highlight it, right-click, 'more...', 'file it in'.

Credit to TheSuccessor.

Last edited by rubiks_cube_guy238 (2011-01-23 19:45:46)


The glass is never half full nor half empty; it is twice as large as it needs to be.

Offline

 

#2 2010-08-26 07:48:51

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

Re: How to make a working [when <> is true] block

Cool. Bump.

Offline

 

#3 2010-08-26 14:32:07

jackrulez
Scratcher
Registered: 2009-08-01
Posts: 1000+

Re: How to make a working [when <> is true] block

This gets added to my collection of hacked blocks.  big_smile


Yawn, another boring text signature. I should really make something better.

Offline

 

#4 2010-08-26 15:34:30

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

Re: How to make a working [when <> is true] block

Nice. I'm using this, and you're on the contributors list for my mod.


/* No comment */

Offline

 

#5 2010-08-26 16:23:40

rubiks_cube_guy238
Scratcher
Registered: 2009-07-02
Posts: 100+

Re: How to make a working [when <> is true] block

TheSuccessor wrote:

Nice. I'm using this, and you're on the contributors list for my mod.

Thanks for giving me credit.  smile


The glass is never half full nor half empty; it is twice as large as it needs to be.

Offline

 

#6 2010-08-27 07:46:51

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

Re: How to make a working [when <> is true] block

And you're expecting me to beleive you that it actually works?
let's see...
*opens scratch source*
*clicks on the devmenu to open browser*
*goes to instructed path*
*makes changes*
*tests*
*dun dun dun...*

IT WORKS!!!
yayz!

i'm using it in Bingo! thanks!
you'll get credit of course!

Offline

 

#7 2010-08-27 07:54:44

rubiks_cube_guy238
Scratcher
Registered: 2009-07-02
Posts: 100+

Re: How to make a working [when <> is true] block

LS97 wrote:

And you're expecting me to beleive you that it actually works?
let's see...
*opens scratch source*
*clicks on the devmenu to open browser*
*goes to instructed path*
*makes changes*
*tests*
*dun dun dun...*

IT WORKS!!!
yayz!

i'm using it in Bingo! thanks!
you'll get credit of course!

lol. thanks.  smile


The glass is never half full nor half empty; it is twice as large as it needs to be.

Offline

 

#8 2010-08-29 10:00:20

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

Re: How to make a working [when <> is true] block

Bump

Offline

 

#9 2010-08-29 10:04:00

rubiks_cube_guy238
Scratcher
Registered: 2009-07-02
Posts: 100+

Re: How to make a working [when <> is true] block

Billybob-Mario wrote:

Bump

Please don't. I already said that the block doesn't work completely.


The glass is never half full nor half empty; it is twice as large as it needs to be.

Offline

 

#10 2010-08-29 10:54:04

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

Re: How to make a working [when <> is true] block

rubiks_cube_guy238 wrote:

NOTE: THIS BLOCK DOES NOT ACTUALLY WORK. I ONLY FIGURED THIS OUT RECENTLY. SORRY.

What do you mean? It works perfectly!


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

Offline

 

#11 2010-08-29 10:56:13

midnightleopard
Scratcher
Registered: 2007-09-13
Posts: 1000+

Re: How to make a working [when <> is true] block

Everytime I work on my old source code mod, someone gets mad at me. So I've pretty much given up squeak for python, but I still like to try out these forum blocks!


http://pwp.wizards.com/5103673563/Scorecards/Landscape.png

Offline

 

#12 2010-08-29 12:06:46

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

Re: How to make a working [when <> is true] block

rubiks_cube_guy238 wrote:

Billybob-Mario wrote:

Bump

Please don't. I already said that the block doesn't work completely.

wht's wrong with it?

Offline

 

#13 2010-08-29 21:05:32

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

Re: How to make a working [when <> is true] block

rubiks_cube_guy238 wrote:

NOTE: THIS BLOCK DOES NOT ACTUALLY WORK. I ONLY FIGURED THIS OUT RECENTLY. YOU WILL SEE WHY IF YOU PUT THE BLOCK IN A SPRITE AND SWITCH SO THAT YOU ARE VIEWING ANOTHER SPRITE.

Oh, I see why now. It also doesn't work in Presentation mode.


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

Offline

 

#14 2010-09-10 12:53:31

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: How to make a working [when <> is true] block

I made one that works! Add the code the the block specs but don't change the WhenHatBlockMorph class. Go to the ScriptableScratchMorph class and add this:

Code:

step
    blocksBin
        submorphsDo: [:each | (each isKindOf: WhenHatBlockMorph)
                ifTrue: [each evaluateCondition ifTrue: [each start]]].
    costume mediaStep ifTrue: [self costumeChanged]

Last edited by MathWizz (2010-09-10 12:54:02)


http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#15 2010-09-10 14:54:44

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

Re: How to make a working [when <> is true] block

So what's wrong with it?


/* No comment */

Offline

 

#16 2010-09-10 15:28:09

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

Re: How to make a working [when <> is true] block

TheSuccessor wrote:

So what's wrong with it?

Make this script:

<when <mouse down> >
<say [You clicked!] >

and then switch to another sprite. It won't work anymore.


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

Offline

 

#17 2010-09-11 06:15:37

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

Re: How to make a working [when <> is true] block

Oh.


/* No comment */

Offline

 

#18 2011-01-18 18:14:12

Pecola1
Scratcher
Registered: 2010-09-06
Posts: 1000+

Re: How to make a working [when <> is true] block

MathWizz wrote:

I made one that works! Add the code the the block specs but don't change the WhenHatBlockMorph class. Go to the ScriptableScratchMorph class and add this:

Code:

step
    blocksBin
        submorphsDo: [:each | (each isKindOf: WhenHatBlockMorph)
                ifTrue: [each evaluateCondition ifTrue: [each start]]].
    costume mediaStep ifTrue: [self costumeChanged]

Wait... there is no blocksBin under scriptablescratchmorph


If you are reading this, please read to the end, because if you don't you won't know what's at the end. Don't just skip to the end though otherwise you won't be able to read the middle, which is most important. Now you must be wondering why you just read all that, the reason is you may have not noticed something, read it again and see if you notice it this time  smile

Offline

 

#19 2011-01-18 18:15:52

Pecola1
Scratcher
Registered: 2010-09-06
Posts: 1000+

Re: How to make a working [when <> is true] block

rubiks_cube_guy238 wrote:

(t6 isKindOf: WhenHatBlockMorph) ifTrue: [t6 color: Color red].

you actually don't need to remove that for some reason. IDK why but it wont turn red.


If you are reading this, please read to the end, because if you don't you won't know what's at the end. Don't just skip to the end though otherwise you won't be able to read the middle, which is most important. Now you must be wondering why you just read all that, the reason is you may have not noticed something, read it again and see if you notice it this time  smile

Offline

 

#20 2011-01-18 18:19:59

hello12345678910
Scratcher
Registered: 2009-07-11
Posts: 100+

Re: How to make a working [when <> is true] block

Pecola1 wrote:

MathWizz wrote:

I made one that works! Add the code the the block specs but don't change the WhenHatBlockMorph class. Go to the ScriptableScratchMorph class and add this:

Code:

step
    blocksBin
        submorphsDo: [:each | (each isKindOf: WhenHatBlockMorph)
                ifTrue: [each evaluateCondition ifTrue: [each start]]].
    costume mediaStep ifTrue: [self costumeChanged]

Wait... there is no blocksBin under scriptablescratchmorph

Just put in in 'other'. that seemed to work for me. you should add this to that tutorial, pecola.


http://tinyurl.com/8yt32o9 http://tinyurl.com/6tgwp5r || Fish = F+I+S+H = 6+9+19+8 = 42<<The answer to Life, the Universe and Everything

Offline

 

#21 2011-01-19 16:56:26

Pecola1
Scratcher
Registered: 2010-09-06
Posts: 1000+

Re: How to make a working [when <> is true] block

hello12345678910 wrote:

Pecola1 wrote:

MathWizz wrote:

I made one that works! Add the code the the block specs but don't change the WhenHatBlockMorph class. Go to the ScriptableScratchMorph class and add this:

Code:

step
    blocksBin
        submorphsDo: [:each | (each isKindOf: WhenHatBlockMorph)
                ifTrue: [each evaluateCondition ifTrue: [each start]]].
    costume mediaStep ifTrue: [self costumeChanged]

Wait... there is no blocksBin under scriptablescratchmorph

Just put in in 'other'. that seemed to work for me. you should add this to that tutorial, pecola.

No I know that but blocks bin isn't even a variable under ScriptableScratchMorph class,

The class variables for ScriptableScratchMorph are:

classVariableNames: 'BlockColorDict BlockSpecDict DefaultBackgroundForm DefaultSpriteForm DoubleSize Experimental ListBlockColor MeowSound OldMeowPrefixReversed PopSound RandomGen Recorder ScratchOrigin TimerStartMSecs '
    poolDictionaries: ''
    category: 'Scratch-Objects'

however the instance ones include blocksBin:

Morph subclass: #ScriptableScratchMorph
    instanceVariableNames: 'objName vars lists blocksBin isClone media costume costumeChangeMSecs filterPack visibility volume tempoBPM sceneStates '


If you are reading this, please read to the end, because if you don't you won't know what's at the end. Don't just skip to the end though otherwise you won't be able to read the middle, which is most important. Now you must be wondering why you just read all that, the reason is you may have not noticed something, read it again and see if you notice it this time  smile

Offline

 

#22 2011-01-23 15:02:11

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

Re: How to make a working [when <> is true] block

MathWizz wrote:

I made one that works! Add the code the the block specs but don't change the WhenHatBlockMorph class. Go to the ScriptableScratchMorph class and add this:

Code:

step
    blocksBin
        submorphsDo: [:each | (each isKindOf: WhenHatBlockMorph)
                ifTrue: [each evaluateCondition ifTrue: [each start]]].
    costume mediaStep ifTrue: [self costumeChanged]

Or, much more simply, in ScratchFrameMorph and ScratchPresenterMorph processWhenConditions, delete the line starting "true".


/* No comment */

Offline

 

#23 2011-01-23 15:56:15

Pecola1
Scratcher
Registered: 2010-09-06
Posts: 1000+

Re: How to make a working [when <> is true] block

TheSuccessor wrote:

MathWizz wrote:

I made one that works! Add the code the the block specs but don't change the WhenHatBlockMorph class. Go to the ScriptableScratchMorph class and add this:

Code:

step
    blocksBin
        submorphsDo: [:each | (each isKindOf: WhenHatBlockMorph)
                ifTrue: [each evaluateCondition ifTrue: [each start]]].
    costume mediaStep ifTrue: [self costumeChanged]

Or, much more simply, in ScratchFrameMorph and ScratchPresenterMorph processWhenConditions, delete the line starting "true".

Does it work on another sprite?


If you are reading this, please read to the end, because if you don't you won't know what's at the end. Don't just skip to the end though otherwise you won't be able to read the middle, which is most important. Now you must be wondering why you just read all that, the reason is you may have not noticed something, read it again and see if you notice it this time  smile

Offline

 

#24 2011-01-24 09:45:48

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: How to make a working [when <> is true] block

TheSuccessor wrote:

MathWizz wrote:

I made one that works! Add the code the the block specs but don't change the WhenHatBlockMorph class. Go to the ScriptableScratchMorph class and add this:

Code:

step
    blocksBin
        submorphsDo: [:each | (each isKindOf: WhenHatBlockMorph)
                ifTrue: [each evaluateCondition ifTrue: [each start]]].
    costume mediaStep ifTrue: [self costumeChanged]

Or, much more simply, in ScratchFrameMorph and ScratchPresenterMorph processWhenConditions, delete the line starting "true".

Ohhhhhhhhh... I'll try that...


http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#25 2011-01-24 11:09:23

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

Re: How to make a working [when <> is true] block

Pecola1 wrote:

Does it work on another sprite?

Yes!


/* No comment */

Offline

 

Board footer