9
\$\begingroup\$

Scratch is a visual programming language. For the sake of counting bytes, Scratch is usually written in scratchblocks2 syntax.

Post tips that specifically apply to Scratch or scratchblocks2.

\$\endgroup\$
  • \$\begingroup\$ A few people might also use the scoring here (in the question post itself), although the two scores definitely don't compete. BTW, Scratch 3.0 will be released in January, but the syntax, AFAICT, isn't going to change much. \$\endgroup\$ – Erik the Outgolfer Nov 9 '18 at 12:44
2
\$\begingroup\$

Abuse the bool type

In Scratch the true and false values are equivalent to 0 and 1, so you can perform arithmetic operations over them. A practical example would be finding the sign of a number:

define f(n
set[r v]to(<(n)>(0)>-<(n)<(0
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Brackets auto-complete

In the scratchblocks3 visual syntax (backwards-compatible with scratckblocks2 syntax), you can auto-complete the brackets.

E.g. The hello, world program:

when gf clicked
say[hello, world]

Can be golfed into:

when gf clicked
say[hello, world

In addition, the end statement of switching structures is auto-completed at the end. So instead of

define f(n
set[i v]to(1
set[o v]to(
repeat(length of(n
repeat((2)-((i)mod(2
set[o v]to(join(o)(letter(i)of(n
end
change[i v]by(1

You could do (-4 bytes)

define f(n
set[i v]to(0
set[o v]to(
repeat(length of(n
change[i v]by(1
repeat((2)-((i)mod(2
set[o v]to(join(o)(letter(i)of(n
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Use a Function if Possible

Where possible, if the challenge says functions are allowed, use them! The syntax for defining a function is almost always shorter than the usual when gf clicked.

For example:

define f(n
say((n)+(1

Over:

when gf clicked
ask()and wait
say((answer)+(1

This also means one doesn't have to use the answer variable, which is quite longer than n.

| improve this answer | |
\$\endgroup\$
-4
\$\begingroup\$

In scratch you need to learn order of operations. Order of operations is learning to put blocks in the right place. All you need for this is confidence

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.