Discuss Scratch

PlatonYa
Scratcher
20 posts

Custom c blocks and hat blocks

that was cool if there was a way how to make hat blocks…
flynnremo2
Scratcher
19 posts

Custom c blocks and hat blocks

i have an idea:
if hat blocks existed in scratch you would need a if statement over define block
this helps because the if statement can expect hat block to trigger at real time
HighlaneGamingStudio
Scratcher
100+ posts

Custom c blocks and hat blocks

Custom hat blocks should probably get rejected because the block below is rejected and custom hats would probably work the same way:

when<>::events hat

Custom C blocks, however, would be an interesting addition to Scratch. A C block's job is to take a script and manipulate it in some way, whether that be only executing it if a boolean returns true or repeating the script a number of times. There's only a few properties of C blocks you could use:
  • Executing a script only if a boolean returns true
  • Repeating a script until a boolean returns true (the repeat (number) times block waits until a hidden iteration variable reaches a certain number)
  • Making a script execute at a different speed
  • Adding case sensitivity to a script
The first two are already implemented with the blocks below:

if <> then

end

if <> then//Checks if a statement is not true for the second slot.

else

end

repeat ()//Repeats over a hidden iteration variable.

end

forever//Repeats until the project is stopped.

end

repeat until <>

end

The third used to allow scripts to run instantly as the C block below but is now available as a feature in custom blocks:

all at once{
}::control

The fourth has been suggested in another topic. All C blocks available as hacks, like forever if, were removed because they have easy workarounds. The only case I can think of where you'd need custom C blocks would be in complex if-check branching, like this:

define if<condition><condition2>run(repeats)times(branch name(::#FD506D)::custom stack)
if <condition> then
repeat (repeats)
branch name[]::custom
end
else
if <condition2> then
repeat ((repeats) / (2))
branch name[or]::custom
end
else
broadcast [end v] and wait
branch name[on end]::custom
stop[all v]
end

…which would create this:

if<><>run()times{
}or{
}on end{
}::custom

This could certainly create some unique code structure, but I'm not sure how much it would be used.
c0der0928
Scratcher
100+ posts

Custom c blocks and hat blocks

i would make it look like this
define {repeat {
my input :: custom
}fprever:: custom} :: custom
forever
my input :: custom
end
KMFpenguin
Scratcher
100+ posts

Custom c blocks and hat blocks

Support! (for both custom c blocks AND custom hat blocks)

The custom hat blocks you breifly mentioned might actually be quite useful. If you find yourself writing a code like this multiple times:
when green flag clicked
forever
if <<touching [mouse pointer v] ?> and <<mouse down?> and <([backdrop# v] of [stage v]) = [2]>>> then
do cucumber stuff here
end
end

It could instead be programmed into a custom hat block!
define Cucumber < > < > < >

define Cucumber <touching [mouse pointer v] ?::sensing> <mouse down?::sensing> <([backdrop number v] of [stage v]) = [2]::operators>


When Cucumber occurs::hat
do cucumber stuff here
realbloxhit900
Scratcher
100+ posts

Custom c blocks and hat blocks

boing

end
HighlaneGamingStudio
Scratcher
100+ posts

Custom c blocks and hat blocks

KMFpenguin wrote:

The custom hat blocks you breifly mentioned might actually be quite useful.
Custom hat blocks with booleans actually already have a workaround that only involves a hat block (it works, I've tried it):

when [timer v] > ((timer) - <boolean::grey>)//You can put a boolean into any reporter slot
VerySmartDummy
Scratcher
100+ posts

Custom c blocks and hat blocks

This may seem cool, but i'm not sure how we could do the code for them
A15breaksheadontable
Scratcher
2 posts

Custom c blocks and hat blocks

when green flag clicked
forever
if <key (shift v) pressed> then
set [speed v] to (15) :: extension
else
set [speed v] to (7.5) ::extension

when green flag clicked
forever
if <mouse down> then
move (speed :: extension) steps
end
if <key (left arrow v) or key (a v) pressed :: sensing> then
move ((0) - (speed :: extension)) steps
end
if <key (right arrow v) or key (d v) pressed :: sensing> then
move (speed :: extension) steps
end
if <key (up arrow v) or key (w v) or key (space v) pressed :: sensing> then
set [gravity v] to (12) :: extension
else
set [gravity v] to (0) :: extension
end

when green flag clicked
forever
change y by (gravity :: extension)
if <not <(gravity :: extension) = (0)>> then
change [gravity v] by (-0.5) :: extension

Last edited by A15breaksheadontable (Oct. 10, 2025 12:50:45)

pippy2011eight
Scratcher
100+ posts

Custom c blocks and hat blocks

So like this?:
when bagel eaten:: custom :: hat
broadcast [eat another bagel v]

bounce (27) times unless bagel =(){
}::control :: custom

If so, support

Powered by DjangoBB