Molang Variables in YSM: Complete Beginner Guide
Molang variables allow your Yes Steve Model (YSM) creations to dynamically react to in-game player actions, such as looking around, walking, or taking damage. By reading and storing data like movement speed or health, you can create natural physics and responsive animations for your custom models.
What Are Molang Variables and Why Do They Matter?
Variables are readable parameters in Minecraft that track a player's real-time status and behavior, including camera pitch, movement speed, and current health. By referencing these parameters inside your animation expressions, you can drive custom bone movements automatically.
Why it matters: Without variables, animations are completely static and ignore what happens in the world. Using variables solves common visual bugs and adds realistic secondary motion without requiring manual triggers from the player.
- Prevent clipping: Read the player's head pitch so that when the player looks up, the back hair rotates backward to cancel out the tilt, preventing the hair from clipping straight through the chest.
- Add gravity effects: Monitor the player's vertical velocity so that hair and clothing float upward automatically whenever the player is falling.
The 4 Types of Variables in YSM
YSM uses four distinct variable prefixes depending on whether you need to only read game data or store your own custom values, as well as how long that data needs to last.
Read-only queries (query.) only read live data from the entity or game and cannot be overwritten. If you need to calculate and save your own numbers, you must use writable variables like entity, temporary, or roaming variables.
- query. (Read-only): Tracks real-time entity or game states. You can read these, but you cannot assign new values to them.
- variable. (Entity variable): Both readable and writable. Stored directly on the entity, and you must assign a value to write to it.
- temp. (Temporary variable): Both readable and writable. Used for short-term calculations; it is destroyed immediately after a single animation loop finishes.
- variable.roaming. (Persistent variable): Works just like a standard entity variable, except its value does not reset when the player exits the game or switches dimensions.
Variable Shorthands and Abbreviations
You can shorten the four main variable prefixes to keep your Molang expressions clean and easy to read, which is especially helpful when writing long math formulas in Blockbench.
Only the four core prefixes below support abbreviation; any other identifiers must be written out in full.
query. -> q.
variable. -> v.
variable.roaming. -> v.roaming.
temp. -> t.Assigning and Initializing Entity Variables
Entity variables start with an initial value of null until you explicitly assign a number to them using the = operator. Why it matters: Doing math with a null variable can cause unexpected animation behavior, so you must always ensure a variable has a valid starting value.
You can safely initialize a potentially null variable using the ?? null-coalescing operator. When you write variable.jump=variable.jump??1, YSM checks if variable.jump is null; if it is null, it sets the value to 1, and if it already has a value, it leaves the existing value unchanged.
variable.jump=variable.jump??1Practical Example: Locking State for a Jump-Attack Animation
Entity variables are essential when you want to capture a split-second player state at the start of an animation and hold onto it. While query.is_jumping tells you if a player is jumping right now (returning 1 in the air and immediately turning to 0 the moment the player touches the ground), its real-time nature can interrupt an animation mid-play.
Suppose you want to animate a vanilla critical jump-attack (hitting while falling from a jump) and need the whole animation to play out even if the player lands halfway through. By saving query.is_jumping into variable.jump at the very beginning of the animation, you lock that state in place.
- At the start of the animation, assign the live query to an entity variable: variable.jump=query.is_jumping.
- If the player is jumping when the animation begins, variable.jump becomes 1.
- Even when the player lands and query.is_jumping drops back to 0, variable.jump stays at 1 until you explicitly assign a new value to it.
variable.jump=query.is_jumpingQuestions
Why does my animation break when the player changes dimensions or relogs?
Standard entity variables (variable.) reset when leaving the world or switching dimensions. If you need a toggle or state to persist across dimensions and game restarts, use variable.roaming. (or v.roaming.) instead.
What is the difference between variable. and temp.?
Both can be read and written to, but temp. (t.) is wiped at the end of a single animation evaluation cycle, making it ideal for quick math helpers. An entity variable (variable. or v.) keeps its value across frames until you overwrite it.
Why can't I change the value of a query. variable?
Variables starting with query. (or q.) are strictly read-only because they report live facts from the Minecraft engine. To manipulate or store a query's value, copy it into an entity variable using = (for example, v.jump=q.is_jumping).
What does the ?? operator do in YSM Molang?
It provides a fallback default value when an entity variable is still null. For example, v.state=v.state??0 sets v.state to 0 only if it has never been assigned a value before.