Discuss Scratch

caesarion
New to Scratch
15 posts

Semantics of Hat Blocks

Hey scratchers!

Lets assume I have an extension hat block that just returns true. Then I put a block under the hat, say this block:
play sound [ v]

Do you think it should play the sound only once or in a loop?
I tried it out and it is played only once. The hat block “fires” only if the returned value changes(!!) to true. I expected a different behavior, such as the green flag hat block. This one is executed in a loop, as long as the green flag is clicked!

This code makes it play in a loop, since the returned value is flipping:
if(ext.flip) {
ext.flip = false;
return true;
}
else{
ext.flip = true;
return false;
}

So why this differentiation between extension hat blocks and normal hat blocks?
What do you guys think about that? Should I create an issue? Or is here any scratch developer who might help? Bug or feature??

Greetz
caesarion
scratchisthebest
Scratcher
1000+ posts

Semantics of Hat Blocks

I don't think there is a difference. For example, see this script:
when green flag clicked
reset timer

when [timer v] > (5)
turn cw (15) degrees
Five seconds after the green flag is clicked, the sprite will rotate 15 degrees, but won't continually spin.

I am a Lava Expert
caesarion
New to Scratch
15 posts

Semantics of Hat Blocks

You are right, I am mistaken. Of course the green flag clicked hat block is not executed in a loop. Nevertheless, a custom block that returns always true should execute all its children blocks in a loop, or no?

Powered by DjangoBB