Molang in YSM: Introduction
Molang is a simple expression language originally created by Mojang for Minecraft Bedrock Edition animations. In Yes Steve Model (YSM), it allows creators to replace static keyframe numbers with dynamic logic that reacts to in-game player actions. This guide covers how Molang works in YSM, practical animation examples, persistent variables, and in-game debugging commands.
What is Molang and Why Does It Matter?
Standard Bedrock animations work by setting fixed numbers for position, rotation, or scale at specific keyframes on a timeline, and the game calculates the smooth transition (tweening) between them. Molang lets you replace those fixed keyframe numbers with dynamic math and game data.
Why does this matter? Without Molang, an arm swing animation always moves the exact same distance. With Molang, you can make the arm swing 30 degrees when the player holds an item, and 60 degrees when their hand is empty, all within a single animation.
Since version 1.2.0, YSM supports almost all official Bedrock Molang features. These include string types, custom variables, the null-coalescing operator (??), binary conditional operators, aliases, complex expressions, scope delimiters ({}), loops (loop, continue, break, and for_each, though for_each is not currently used), structs, and arrow expressions (->).
Practical Example 1: Hiding and Showing Model Parts
One of the most common uses for Molang in YSM is toggling the visibility of specific bones based on player equipment. You can hide any model component by setting its X, Y, and Z scale to 0.
For example, if you want a custom helmet bone to appear only when the player equips a helmet in Minecraft, you can type the query below directly into the X, Y, and Z scale fields of that bone in Blockbench.
The query returns 1 when the player wears a helmet and 0 when they do not. This automatically scales the part between 100% (visible) and 0% (invisible) in real time.
ysm.has_helmetPractical Example 2: Fixing Long Hair Clipping
Long hair attached to the head bone often clips straight into the character's upper body when the player looks up. You can solve hair clipping using a Molang conditional expression (ternary operator) on the hair bone's pitch rotation.
A conditional expression follows the format: condition ? result_if_true : result_if_false. We want the hair to hang straight down when looking up (canceling out the head rotation), but rotate normally with the head when looking down.
In YSM, the player's head pitch ranges from -90 degrees (looking down) to 90 degrees (looking up). When the pitch is greater than 0, we apply the negative value of the head pitch to the hair so the rotations cancel out. When it is 0 or less, we apply 0 additional rotation.
- Select your long hair bone in Blockbench (which should be a child of the Head bone).
- Add a rotation keyframe in your base idle or parallel animation.
- In the X-axis (pitch) rotation field, enter the conditional Molang expression below.
(ysm.head_pitch > 0) ? -ysm.head_pitch : 0Differences Between YSM and Bedrock Molang
While YSM closely follows official Bedrock Molang standards, there are a few technical differences you must keep in mind when writing complex scripts:
Uninitialized variables default to null. You can detect them using the null-coalescing operator (??), and if they are used directly in math calculations, they are treated as 0 or false.
Structs cannot be nested inside other structs.
Standard variables are wiped frequently. All normal variable storage is cleared whenever a player switches models, respawns, teleports to certain dimensions, logs out and back in, or performs similar state-resetting actions.
Persistent Data with Roaming Variables
Because normal variables reset on death or dimension changes, YSM provides a special variable type for data that needs to stick around. Variables written in the format v.roaming.xxx persist across dimension changes, respawns, and relogging.
Why does this matter? Roaming variables are synchronized between players and saved directly to the world save via server capabilities, making them essential for toggles like custom outfits or persistent weapon states.
You must write the full prefix v.roaming.xxx (you cannot shorten it to v.r.xxx). Additionally, roaming variables have strict technical limits: a model can use at most 64 roaming variables (and all models share these 64 slots), the variable name cannot exceed 16 characters, and they can only store float numbers.
v.roaming.outfit_state = 1;In-Game Debugging Commands
Testing Molang by repeatedly exporting models and guessing values is slow. YSM includes built-in client and server commands to execute and watch Molang expressions live in-game.
To test a one-off expression on your local player and print the result in the chat box (works in singleplayer only), use the client execute command. For multiplayer servers, admins can execute an expression on a specific player, though it will not print a chat result.
You can also pin expressions to a live on-screen debug overlay that updates in real time. When adding a watch expression, choose pre to evaluate it before animation updates, or post to evaluate it after animation updates.
# Execute locally and print result to chat (Singleplayer only)
/ysmclient molang execute <expr>
# Add a live expression to the custom debug screen
/ysmclient molang watch add [pre|post] <name> <expr>
# Remove a watched expression or clear all watched entries
/ysmclient molang watch remove <name>
/ysmclient molang watch clear
# Execute on a target player (Multiplayer, requires admin permissions)
/ysm molang execute <player> <expr>Questions
Why do my custom Molang variables reset every time I die or enter the Nether?
Standard Molang variables in YSM are cleared whenever you respawn, switch models, relog, or change dimensions. If you need a value to save and sync across these events, use a roaming variable formatted as v.roaming.your_name.
Can I shorten v.roaming.xxx to v.r.xxx like I shorten variable.xxx to v.xxx?
No. YSM requires the full v.roaming.xxx prefix to recognize it as a persistent roaming variable. Also ensure the name after the prefix is 16 characters or fewer and only stores a float.
How do I open the debug screen after using /ysmclient molang watch add?
In YSM version 2.3.0 and newer, press Alt + B once to toggle the custom debug screen. If you are using version 2.2.2 or older, you must press Alt + B twice.
What value does a variable have before I assign anything to it?
In YSM, uninitialized variables hold a null value. You can check for this using the ?? (null-coalescing) operator, or use it directly in math where it will automatically count as 0 or false.
Next: Convert Models Between Yes Steve Model and Touhou Little Maid →