Skip to main content

Differences from JavaScript

Your code runs as Scratch blocks, so it follows Scratch's rules. Here's what to keep in mind.

TopicWhat happens
break, continue, switchNot supported. Use a flag in the loop condition, or return from a function.
Variable valuesKept between runs (green flag clicks). Reset them in whenFlag.
Variables inside functionsBecome sprite variables, so they aren't safe across recursion.
Value-returning callsAt most one per statement. Split f(a) + f(b) into two variables. Loop and waitUntil conditions may call functions.
== / ===Scratch equality: compares numbers numerically, text case-insensitively ("A" === "a" is true).
%Result takes the sign of the divisor (-1 % 3 is 2).
sin, cos, ...Use degrees.
FunctionsBelong to their sprite. Share code through src/lib/ or the engine, which copy functions into each sprite that uses them. To trigger code in another sprite, use broadcast.
ObjectsState objects ({ score: 0 }) and classes. Objects are created when the project is built: make them with new at the top of a file, and use clones when you need many at runtime.
me.visibleCan be set but not read (Scratch has no block for it). Keep it in a variable, or use Camera.onScreen.
Sprite positionsScratch keeps sprites on stage, so a sprite can't move fully off screen. Hide it instead (Camera.place does this).
ListsHold numbers and text. No nested arrays.
TimingLike Scratch, loops yield once per frame unless the function is marked /** @warp */.