Tokyube Code Blocks
Tokyube Code Blocks is the visual scripting layer of TokyubeVoxelVerse — a powerful, non-restrictive visual programming system built on top of JavaScript. Drop blocks together to build anything from a one-line trigger to a full multiplayer minigame, complete with named persistent variables, typed entity references, timed events, networked components, and direct access to the voxel world.
Overview
Tokyube Code Blocks is not a watered-down beginner tool. Every block compiles to clean, readable JavaScript that runs through the same runtime as the rest of the engine — no sandbox limits beyond what the engine itself enforces. That means:
- Full expressive power. Conditionals, loops, recursion, arithmetic, string manipulation, function definitions, and event-driven flow. If you can express it in JavaScript, you can express it in blocks.
- Named persistent variables. Save numbers, strings, positions, voxels, components, FBX entities, and full Tokyube entity references by name. Persisted scopes survive restarts; transient scopes wipe with the world reload.
- Typed Variables. Variables are type-checked at compile-time so you can't accidentally treat a position as an entity — surface errors before the script ever fires.
- Real-time concurrency. Animate, delay, repeat, and broadcast events without blocking the main thread; the runtime handles scheduling deterministically across single-player and multiplayer.
- First-class multiplayer. Triggers fire on the host, replicate to peers, and stay consistent without extra plumbing. Events broadcast to entities, components, or every connected player.
- Native voxel operations. Place, remove, query, and shape voxels in bulk. Cubes, spheres, lines, walls — all available as primitive blocks.
Getting Started
- Enter Script Mode by holding Tab.
- Click on the voxel, component, FBX entity, or TokyNode you want to script. The Code Blocks workspace opens.
- Drag blocks from the left-side toolbox into the workspace. Connect them top-to-bottom for sequential execution; nest blocks inside slots to pass values.
- Press SAVE — the script attaches to the selected target and starts running according to its triggers.
Every script has at least one entry point — usually a
world_start block, a trigger block, or a
event_on_receive. Without an entry point a script
can compile but never runs.
The Workspace
The Code Blocks workspace is built on Google Blockly. The Tokyube extensions on top add:
- The full custom toolbox (24 categories, 100+ blocks).
- A Saved Scripts Library for pulling previously authored scripts onto a new target.
- An Attach From Library shortcut that re-attaches any saved script to a fresh target without opening the editor.
- A live Console panel that
streams
console_logoutput as you play. - Per-script and per-workspace search so you can find any block by typing its name.
Logic
Conditionals, comparisons, and boolean operators. Logic blocks return values that fit into any logic-shaped slot in another block.
else if arms with the gear icon.=, ≠, <, ≤, >, ≥.Loops
Standard control flow plus a few engine-specific helpers. All loops are non-blocking — long iterations yield to the runtime.
entity_all.Math
Arithmetic, trigonometry, randomness, and constants.
Text
String creation, manipulation, and conversion.
Variables
Standard Blockly variable scope. Pair this with the dedicated Typed Variables blocks for engine-aware types.
Functions
Define reusable procedures and call them from anywhere in the script.
Voxel Actions
Place, remove, query, and inspect voxels.
true if a voxel exists at the position.Shapes
Bulk voxel placement primitives — all stream as a single operation in multiplayer.
Animation
Move and tween entities along paths with delays and timing helpers. Animations run on a scheduler — they don't block other scripts.
Entity
Reference, query, and modify Tokyube entities (mobs, items, attached FBX, TokyNodes).
entity_all.Persistence
Named save/load that survives world reloads.
scripts.json save file. Use it for
long-running counters (kills, score, unlocked stages) and for any
state you want to survive a server restart.Player
Read and act on the player's state.
Display
Show text on a display voxel/component.
Teleport
Move players, entities, or components instantly.
World
World-level lifecycle hooks.
Triggers
Run code in response to player or entity activity. Triggers
are the second-most-common entry point after
world_start.
Attachment
Bind entities, components, and FBX objects to parents so they move together. Pairs with Events for attached behaviors.
Events
Send and receive named events. Events are the cleanest way to decouple scripts that need to talk to each other.
on_receive body, returns the event's payload.Console
Debugging output streamed to the live console panel.
FBX Entities
External 3D meshes (.OBJ / .FBX) attached to the world. Treat them like any other entity for transform, but with extra per-mesh helpers.
Typed Variables
Engine-aware variable storage. Each typed-variable block accepts only its declared type, so a position never gets stored in an entity slot — type errors surface in the editor instead of at runtime.
null via the
matching var_set_* block.TV & Video Control
Drive the in-world TV component or any video-component instance. All commands sync across multiplayer (the host is authoritative on playback state).
Video Component blocks
TokyPhone TV control blocks
Example Scripts
These are the same 17 starter scripts shipped in the in-engine Saved Scripts Library. Click any tile in the Starter Scripts row at the bottom of the in-world Library to copy one of these into a free slot, then edit it from there.
BNC — Bounce
Makes the entity voxel bounce up 3 blocks and back down repeatedly.
PLS — Pulse Up Down
Moves entity up 1 block then back down every second.
HLO — Hello World
Logs "Hello World!" to the console. Simple test script.
TWR — Place Tower
Builds a 5-block tall stone tower above this entity.
MVR — Move Right 5
Smoothly animates this entity 5 blocks to the right over 1 second.
SPN — Spin Around
Moves entity in a square pattern around its starting position.
TRG — Trigger Launch Pad
When a player walks into the trigger zone, launch them 5 blocks up.
EVT — Event Demo
When the world starts, register to receive the
"launch" event on the player (which launches them
5 blocks high), then immediately send the "launch"
event to the player.
TPB — Teleport to Sakura Biome
When the world starts, wait 2 seconds then teleport the player to the Sakura biome (if one exists in this world).
DSP — Display Text on Component
When the world starts, set the text of a Text component at position (0, 20, 0) to "Hello World!". Edit the x/y/z to match your Text component's position.
TVP — TV Playlist (2 Videos)
When the world starts: play video 1, then when it ends play
video 2, then loop. Edit VIDEO_1 /
VIDEO_2 to your own YouTube or .mp4 links.
tv on completed after each play so the playlist loops indefinitely.RH+ — Equip in Right Hand
Attach this FBX entity to the player's right hand when the world starts. Toggle ATTACHABLE on in the FBX entity's properties first.
LH+ — Equip in Left Hand
Same as RH+, but binds to the left hand anchor.
HAT — Wear as Hat (Head Anchor)
Attach this FBX to the head — works great for hats, helmets, halos.
CST — Wear on Chest
Attach this FBX to the chest — backpacks, body armor, badges.
PIK — Pick Up on Trigger
When the player walks over this FBX entity, the FBX equips to their right hand. Toggle ATTACHABLE on first.
UNQ — Equip Then Auto-Detach
Equip this FBX to the right hand, then detach it after 5 seconds — handy for temporary boost items / power-ups.
Collaborative Code Blocking
The Code Blocks workspace is being extended to support multiple cursors at once, so two to four collaborators can edit the same script in real time:
- Operational transform on block edits. Two creators dragging blocks into the same workspace at the same time merge cleanly — neither one's move silently clobbers the other's. Insertions, deletions, and slot changes all OT independently.
- Per-collaborator cursors. Each collaborator's selected block highlights in their assigned color so you can see who is about to do what before they commit.
- Per-script lock toggles. Mark a script solo if you want to focus alone for a moment; flip it back to open when you're ready for partners again.
- Live console mirroring. When a
collaborator presses Run, every connected editor sees the
same
console_logoutput — making bug-finding a shared activity instead of a side conversation. - Shared script library. The Saved Scripts Library is per-world; collaborators in the same world already share saved scripts, components, and FBX attachments — Collaborative Code Blocking simply removes the "one editor at a time" gate.
- Co-authored persistence. Typed variables and persistent saves authored by either collaborator land in the same world save, with audit metadata so you can see who introduced what later.
The networking primitives this rides on top of (host-authoritative triggers, shared event bus, per-peer presence) are the same ones powering the regular multiplayer layer — so the same world that runs your finished scripted game can also be the one you author it inside, together.
Tips & Best Practices
- Prefer events over polling. A
repeat foreverwith a delay works, butevent_on_receiveis cheaper and multiplayer-clean. - Use Typed Variables for state. They persist, type-check, and make the script self-documenting.
- Wire the Console early. Drop a
console_logat every interesting branch while prototyping — pull them out once the script is shipping. - Save scripts you like. The Saved Scripts Library carries scripts between worlds; once a piece of logic works, save it and re-attach instead of re-authoring.
- Test in single-player, ship in multiplayer. Triggers and events behave the same across both — but animation timing and event ordering can surprise you when latency is involved. Always do a final pass with a peer connected.
- Comment with Console. A
console_log "section: enemy spawn"at the top of a sub-routine reads as a section header without needing real comments.