Skip to content

Standard library overview

Katnip’s standard library is not compiler magic — it is a set of .knip declaration files bundled into the compiler at build time. Each procedure is an empty body with an @opcode decorator naming the Scratch block it emits:

proc forward(@opcode = "motion_movesteps", steps: num) -> void {}

That means the standard library is readable, and you can see exactly which Scratch block any call becomes.

Namespace Covers Status
prelude wait, stop, len, Key, true/false — no namespace prefix 🟢 mostly
events hats, broadcasts 🟢
motion movement, turning, position 🟢
looks say/think, costumes, size, effects, layers 🟢
sensing touching, mouse, keys, timer, ask/answer 🟢
pen the pen extension 🟢
clone clone lifecycle 🟢
list list methods 🟡
dict dict methods 🔴
str string methods 🟡
math constants and pow 🟡
console log, warn, error, input 🔴

🟢 reaches real Scratch blocks · 🟡 partly · 🔴 type-checks but fails the build

Each page lists signatures as declared. A ✅ means it compiles all the way to a .sb3 today; a ⛔ means it type-checks and then fails, with a note on what to write instead.

Anything whose first parameter is named self is a method, callable either way:

scores.contains(4); # method form ✅
list.contains(scores, 4); # namespace form ⛔ fails at codegen

Both type-check, but only the method form builds today — the namespace form makes codegen look for a variable called list. Use the receiver form throughout.

Lots of stdlib procedures take an enum, because the Scratch block behind them has a dropdown. There are two ways to write one, and they compile to the same blocks:

motion.setRotationStyle(motion.RotationStyle.LEFT_RIGHT); # the member
motion.setRotationStyle("left-right"); # a literal that matches it

A literal that misses is an error listing the members, with a did-you-mean. Every page here gives the full member table so you can use either style.

Enums declared inside a namespace stay out of global scope, so reach them through the namespace. Prelude enums have no namespace and are bare names:

motion.Target.RANDOM # ✅
Target.RANDOM # error: 'Target' is not defined
Key.SPACE # ✅ prelude
stop(StopType.ALL); # ✅ prelude