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, now
217 custom blocks strong. 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, per-player
cross-world variables, full 2D UIs, and direct access to the voxel
world. The toolbox organizes it all into FBX / Component / Logic /
Math / Variables categories with world-picker dropdown blocks.
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.
Code Blocks are authored inside the world,
attached to voxels, components, FBX entities, or TokyNodes via
Script Mode. They
save with the world and travel with the entity they're attached
to.
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_log output 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.
if / else if / elseBranch on a boolean. Stack multiple else if arms with the gear icon.
comparisonCompare two values: =, ≠, <, ≤, >, ≥.
and / orCombine two booleans into one.
notInverts a boolean.
true / falseConstant booleans.
nullThe empty value — useful when a slot accepts any object reference.
test ? a : bTernary expression — return one of two values based on a boolean.
Loops
Standard control flow plus a few engine-specific helpers. All
loops are non-blocking — long iterations yield to the runtime.
repeat N timesRun the body a fixed number of times.
while / untilRun the body while a condition is true (or until it's true).
for i from a to b by stepCounted loop with a counter variable.
for each item in listIterate over a list. Pairs cleanly with entity_all.
break / continueExit a loop early or skip to the next iteration.
Math
Arithmetic, trigonometry, randomness, and constants.
numberLiteral number.
arithmeticAdd, subtract, multiply, divide, modulo, power.
single opSquare root, absolute value, negate, ln, log10, e^, 10^.
trigsin, cos, tan, asin, acos, atan.
round / floor / ceilingStandard rounding modes.
random integer / fractionRandom integer in a range, or a 0.0–1.0 float.
constantsπ, e, φ, √2, infinity.
Text
String creation, manipulation, and conversion.
"text"Literal string.
create text withConcatenate any number of values into one string. Polymorphic — converts numbers and positions to display text.
length / is emptyString inspection.
find / get substringLocate or extract substrings.
to upper / lower / trimStandard case + whitespace handling.
replaceFind-and-replace inside a string.
Variables
Standard Blockly variable scope. Pair this with the dedicated
Typed Variables blocks for engine-aware
types.
create variable…Define a new local variable. Available in any expression slot.
set / changeAssign a value or increment/decrement.
getRead a variable's value.
Functions
Define reusable procedures and call them from anywhere in the
script.
to do somethingDefine a procedure. Can take any number of named parameters.
to do something with returnLike above, but returns a value.
if returnEarly-return out of a function based on a condition.
callInvoke a defined procedure. Auto-generated when you create the procedure.
Voxel Actions
Place, remove, query, and inspect voxels.
voxel_placePlace a voxel of a chosen type at a position.
voxel_removeRemove the voxel at a position.
voxel_moveTranslate a voxel from one position to another.
voxel_existsReturns true if a voxel exists at the position.
voxel_get_typeReturns the voxel-type identifier at a position.
voxel_at_entityReturns the voxel an entity is currently standing on.
Shapes
Bulk voxel placement primitives — all stream as a single
operation in multiplayer.
shape_cubeFill a rectangular prism with a voxel type.
shape_sphereFill a sphere of a given radius.
shape_lineDraw a line of voxels between two positions.
shape_wallBuild a wall along an axis with a chosen height and length.
Animation
Move and tween entities along paths with delays and timing
helpers. Animations run on a scheduler — they don't block other
scripts.
timing_delayWait N seconds before continuing.
timing_repeatRun a body every N seconds; cancellable.
timing_cancelCancel a previously scheduled timer by handle.
animate_moveLinearly move an entity by a delta over a duration.
animate_entity_toTween an entity from its current spot to a target position.
animate_pathWalk an entity through a sequence of waypoints.
animate_bounceSpring/bounce easing helper for organic motion.
make_position / make_pathConstruct positions and waypoint lists inline.
Entity
Reference, query, and modify Tokyube entities (mobs, items,
attached FBX, TokyNodes).
entity_thisThe entity this script is attached to.
entity_get_by_nameLook up an entity by its assigned name.
entity_get_position / set_name / get_name / get_typeStandard accessors.
entity_allReturns the list of all entities currently loaded.
entity_at_positionReturns the entity at (or nearest to) a position, or null.
entity_foreachIterate over a list of entities; combines with entity_all.
entity_distanceDistance between two entities.
entity_offset_positionOffset an entity's position by a delta vector.
distance_xyz / distance_player_toDistance helpers when you only have raw coordinates.
Persistence
Named save/load that survives world reloads.
data_saveSave a value under a key. Scope is per-world by default.
data_loadLoad a saved value (or null if it's never been written).
Persistence is the bridge between scripts and
the world's 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.
player_positionReturns the local player's current position.
player_attach_entity / detach_entityParent an entity to the player so it follows them.
player_attach_fbx_to_body / detach_fbxAttach an external FBX mesh to a body bone (head, hand, etc).
Display
Show text on a display voxel/component.
display_set_textSet the visible text on a display target.
Teleport
Move players, entities, or components instantly.
teleport_playerMove the player to a position.
teleport_to_biomeFind the nearest tile of a chosen biome and teleport there.
teleport_entityMove an entity to a position.
teleport_componentMove a component instance to a position.
World
World-level lifecycle hooks.
world_startFires once when the world finishes loading. The most common script entry point.
Triggers
Run code in response to player or entity activity. Triggers
are the second-most-common entry point after
world_start.
trigger_on_enterFires when a player enters the trigger volume of the script's owner.
trigger_is_insideReturns whether the player is currently inside the trigger zone.
trigger_launch_playerApply a velocity to the player (jump pads, cannons, knockback).
trigger_voxel_enterFires when a voxel of a given type is entered.
trigger_entity_enterFires when any entity (or one of a given type) crosses the volume.
trigger_component_enterFires when a component instance enters the volume.
Attachment
Bind entities, components, and FBX objects to parents so they
move together. Pairs with Events for
attached behaviors.
player_attach_entity / detach_entityAttach/detach an entity from the player.
player_attach_fbx_to_body / detach_fbxAttach/detach an FBX mesh to a player bone.
Events
Send and receive named events. Events are the cleanest way to
decouple scripts that need to talk to each other.
event_send_to_entitySend an event with optional payload to a specific entity.
event_send_to_componentSend an event to every instance of a component.
event_broadcastSend to every script in the world.
event_send_to_*_delayVariants that fire after N seconds.
event_on_receiveSubscribe to an event by name. Body runs each time the event fires on this script's owner.
event_dataInside an on_receive body, returns the event's payload.
Console
Debugging output streamed to the live console panel.
console_logPrint any value to the in-world Console. Tagged with the script's owner so logs are easy to attribute.
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.
fbx_get_entity / get_currentResolve an FBX entity by name or get the script's own owner.
fbx_set_position / get_pos / move_toPosition controls.
fbx_set_rotation / rotate_toRotation controls.
fbx_set_scale / scale_toScale controls.
fbx_set_visible / set_collidableToggle rendering and collision.
fbx_on_player_enter / on_player_exitVolume triggers for FBX meshes.
fbx_open_door / close_doorDoor-mode helpers for hinged FBX meshes.
fbx_send_event / on_eventPer-FBX event channels.
fbx_set_property / get_propertyFree-form per-mesh metadata storage.
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.
var_set_entity / get_entityStore and retrieve entity references by name.
var_set_number / get_numberNumeric typed variable.
var_set_string / get_stringStrings.
var_set_position / get_position3D positions.
var_set_fbx / get_fbxFBX entity references.
var_set_component / get_componentComponent instances.
var_set_voxel / get_voxelVoxel positions or types.
Typed variables are persistent by
default. To wipe one, write 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
play / pause / stop / resume / seekStandard transport controls scoped to a single video component.
get_video_timeCurrent playback time in seconds.
set_video_volume / set_video_urlVolume (0–1) and source URL setters.
on_video_completedBody fires when the video reaches the end.
TokyPhone TV control blocks
tv_play / tv_pause / tv_stop / tv_resume / tv_seekSame transport, but routed through the in-world TV control system used by TokyPhone.
tv_set_url / tv_set_volumeSource URL and volume.
tv_get_timeCurrent playback time.
tv_on_completedFires when a TV-routed video reaches the end.
play / pause / resume / stop / seek_video_componentTransport controls aimed at a specific video-player component instance.
UI
Build full 2D interfaces — panels, buttons, images, drag &
drop — that render over the world for a player. The biggest
category in the language at 22 blocks.
ui_open / ui_open_at / ui_close / ui_is_open / ui_clearOpen a UI for a player (optionally at a position), close it, test it, or clear its contents.
ui_rect / ui_text / ui_image / ui_outline / ui_gapDraw elements: rectangles, text, images, outlines and spacing.
ui_move / ui_remove / ui_draggableReposition or remove elements; make an element draggable.
ui_on_click / ui_on_hover / ui_on_key / ui_on_drag_start / ui_on_dropEvent hooks for interaction.
ui_event_x / ui_event_y / ui_event_key / ui_event_dragRead the coordinates, key or drag payload inside a UI event.
HUD
Lightweight on-screen text without building a full UI.
hud_set_text / hud_show_messagePin text to a HUD slot, or flash a temporary message.
hud_clear / hud_clear_allClear one HUD slot or everything.
display_set_text / text_linebreakDrive in-world display text, with explicit line breaks.
Environment
Per-world atmosphere, fully scriptable.
set_sky_color / set_water_color / set_water_gradient2 / set_water_gradient3Sky and water colors — flat or 2/3-stop gradients.
set_grass_gradient3 / set_grass_gradient3_lowGrass color gradients (with a low-preset variant).
set_weather / set_rain_color / set_lightning_intervalWeather state, rain tint, and lightning frequency.
env_is_night / env_night_blendRead the day/night cycle — boolean night test or a 0–1 blend.
set_reflection_quality / set_dynamic_light / set_imageReflection quality, dynamic light control, and image swapping.
set_camera_view / lock_camera_viewForce or lock the player's camera view.
Spawn & Despawn
Bring structures, images and TokyNodes into the world — and
clean them up again, by tag.
spawn_hallway / spawn_image / spawn_originSpawn procedural hallway prefabs and tagged images at positions.
spawn_tokynode / spawn_tokynode_familySpawn a saved TokyNode, or a whole node family, from your cross-world library.
despawn_tag / despawn_images_tag / despawn_all_structuresRemove spawned things by tag, or all structures at once.
despawn_tokynodes_tag / despawn_all_tokynodesThe TokyNode equivalents.
start_backrooms_maze / stop_backrooms_mazeGenerate (and tear down) an endless backrooms maze around the player.
Laser
Drive the Laser Projector component — 4 gun presets plus full
script control.
laser_set_visible / laser_set_length / laser_set_speedToggle, size and animate the beam.
laser_set_colors / laser_set_animBeam colors and animation preset.
Projectile
Fire things. Pairs with the Projectile Launcher component.
projectile_fire / projectile_fire_named / projectile_launchFire from a launcher (by reference or by name), or launch a projectile directly.
projectile_autoAuto-fire on an interval.
NPC
Script the Tokyube NPC component.
npc_set_type / npc_set_param / npc_head_turnSet which skin/behavior an NPC uses, tune its parameters, and turn its head.
PPV — Per-Player Variables
Cross-world persistent values scoped to each player's account —
the system behind casino chips and card-game stats. Players can
inspect their values in the
TPPV app.
ppv_get / ppv_set / ppv_changeRead, write, or increment a named per-player variable. Values persist across worlds and sessions.
Prefer ppv_set(ppv_get + 1)
style updates for counters — set-to-computed-value is the
engine's canonical increment pattern.
Audio & Pickers
audio_control / audio_set_volume / world_audioControl Audio components and world-level audio.
pick_component / pick_fbx_entity / pick_script_entityDropdown picker blocks listing every instance in the world by name.
component_move / distance_player_to / distance_xyzMove a component; measure distances from the player or between points.
key_on_press / players_in_zone / player_countKeyboard hooks and multiplayer zone/count queries.
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.
repeat every 2000 ms
animate bounce this entity height 3 speed 150
PLS — Pulse Up Down
Moves entity up 1 block then back down every second.
repeat every 1000 ms
animate bounce this entity height 1 speed 200
HLO — Hello World
Logs "Hello World!" to the console. Simple test script.
console log "Hello World!"
TWR — Place Tower
Builds a 5-block tall stone tower above this entity.
for i from 1 to 5
voxel place stone at (this.x, this.y + i, this.z)
MVR — Move Right 5
Smoothly animates this entity 5 blocks to the right over
1 second.
animate entity to (this.x + 5, this.y, this.z) over 1000 ms
SPN — Spin Around
Moves entity in a square pattern around its starting position.
animate path this entity through positions interval 300 ms
make position (this.x + 3, this.y, this.z)
make position (this.x, this.y, this.z + 3)
make position (this.x − 3, this.y, this.z)
make position (this.x, this.y, this.z)
TRG — Trigger Launch Pad
When a player walks into the trigger zone, launch them
5 blocks up.
trigger on enter at (this.x, this.y, this.z)
launch player 5
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.
when world starts
on player receive event "launch"
launch player 5
send event to player "launch" data 0
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).
when world starts
delay 2000 ms
teleport to biome sakura
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.
when world starts
display set text at (0, 20, 0) to "Hello World!"
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.
when world starts
tv set url "https://youtu.be/VIDEO_1"
tv play
on tv completed
tv set url "https://youtu.be/VIDEO_2"
tv play
The runtime version of this script also re-binds 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.
when world starts
attach fbx this fbx to body anchor right_hand
LH+ — Equip in Left Hand
Same as RH+, but binds to the left hand anchor.
when world starts
attach fbx this fbx to body anchor left_hand
HAT — Wear as Hat (Head Anchor)
Attach this FBX to the head — works great for hats, helmets,
halos.
when world starts
attach fbx this fbx to body anchor head
CST — Wear on Chest
Attach this FBX to the chest — backpacks, body armor, badges.
when world starts
attach fbx this fbx to body anchor chest
PIK — Pick Up on Trigger
When the player walks over this FBX entity, the FBX
equips to their right hand. Toggle
ATTACHABLE on first.
trigger on enter at (this fbx.x, this fbx.y, this fbx.z)
attach fbx this fbx to body anchor right_hand
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.
when world starts
attach fbx this fbx to body anchor right_hand
delay 5000 ms
detach fbx this fbx
Each starter ships with both the original
block stack and the generated JavaScript ready to run.
After copying a starter into a slot, hit EDIT
SCRIPT in the library info panel to open the workspace
and customize.
Collaborative Code Blocking
Collaborative code-blocking is a
first-class planned feature.
Collaborative Build itself
is live today — friends in a collab session can already script in
the same world — while the shared same-workspace editor described
below is the planned next step.
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_log output — 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 forever with a delay works, but
event_on_receive is 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_log at 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.