promotional bannermobile promotional banner

JavaScript Ingame

allows you to run javascript ingame
Project Animation

Welcome To Criptonain Industries
by Cript0 panda

This script is a runtime JavaScript execution tool (an "eval" command) built for Minecraft Bedrock Edition's Script API. It allows administrators to run raw JavaScript code directly inside a live world using custom chat commands, while safely tracking and cleaning up background loops and event listeners.
Here is a comprehensive, step-by-step guide on how it works, how to set it up, and how to use it.

๐Ÿ› ๏ธ Prerequisites & Setup
To use this code, you must be working with a Minecraft Bedrock Behavior Pack utilizing the Script API.
1. Requirements
  • Minecraft Version: You must have Beta APIs enabled in your world settings.
  • Manifest Permissions: Your behavior pack's manifest.json needs the @minecraft/server dependency.
  • Player Role: You must be a Game Director (Host/Admin with cheats enabled) to run these commands.
2. Installation
  1. Paste this exact code into your main script file (e.g., main.js or index.js) inside your behavior pack's scripts/ folder.
  2. Launch Minecraft, apply the behavior pack to a world, and ensure Beta APIs are toggled ON in the world creation menu.

๐ŸŽฎ The Registered Commands
The script automatically registers two custom commands using Minecraft's command registry system:
1. /commander:javascript "<your code here>"
Runs a block of JavaScript code inside the engine.
  • Permission Level: Game Directors only.
  • Parameter: A mandatory String containing the code you want to run.
  • Note: Because the parameter is a string, your command code must be enclosed in double quotes " " if it contains spaces.
2. /commander:eventcleanup [message]
Stops and unregisters all running background tasks generated by the execution tool.
  • Permission Level: Game Directors only.
  • Parameter: An optional Boolean (true or false). If true (or left blank), it prints a success message in chat detailing what was cleaned up.

๐Ÿ’ป Available Variables (The Environment)
When you pass code to /commander:javascript, the script compiles it into a dynamic function. It injects four special global variables that you can use instantly in your code:
  • world: The standard @minecraft/server world object. Used to broadcast messages, fetch players, or get dimensions.
  • player: The specific player entity who executed the command.
  • system: The standard @minecraft/server system object. Used for scheduling ticks.
  • manager: A custom wrapper class built into this script. Always use this instead of standard API signals if you want your background loops to be cleanable!

๐Ÿš€ Step-by-Step Usage Examples
1. Simple Commands (Single Action)
For basic tasks that execute once instantly, write your code inside quotes.
  • Send yourself a private message:
    text
    /commander:javascript "player.sendMessage('Hello from Javascript!');"
  • Broadcast a global alert to the server:
    text
    /commander:javascript "world.sendMessage('§e[Server Warning] This server restarts soon.');"
    
     
2. Intermediate Commands (Multi-line & Dimensions)
Because the command parser expects a continuous string, multi-line code can either be written on one line separated by semicolons ;, or written in a command block.
  • Give yourself a diamond block at your exact feet:
    text
    /commander:javascript "const dim = player.dimension; const loc = player.location; dim.getBlock(loc).setType('minecraft:diamond_block');"
    
     
3. Advanced Commands (Background Loops & Events)
Normally, if you run a continuous interval or subscribe to an event via a custom command, it will run forever until you restart the world. This script solves that problem using the manager variable.
  • Create a repeating loop (e.g., constantly heal yourself every 1 second / 20 ticks):
    Instead of system.runInterval(), use manager.runInterval():
    text
    /commander:javascript "manager.runInterval(() => { player.addEffect('regeneration', 40, { amplifier: 1 }); }, 20);"
    
  • Subscribe to a game event safely (e.g., detect when players chat):
    Instead of world.afterEvents.chatSend.subscribe(), use manager.subscribe():
    text
    /commander:javascript "manager.subscribe(world.afterEvents.chatSend, (data) => { world.sendMessage(`§7${data.sender.name} typed a message.`); });"
    
     

๐Ÿงน How to Clean Up Your Scripts
If you started loops or event tracking via the manager using the examples above, your server background performance will slowly degrade as you test more code.
To clear everything out and start fresh without restarting your Minecraft world, run:
text
/commander:eventcleanup<button id="" class="FTsWP RmjGdc IsqrXb" aria-label="Copy code text to clipboard." data-tooltip-classes="undefined" data-is-tooltip-wrapper="undefined" data-tooltip-id="undefined" aria-describedby="" data-sfc-cp="" data-wiz-attrbind="disabled=iVcVJb_8p/ggNWmb" data-sfc-root="c" data-complete="true" data-copy-service-computed-style="font-family: Arial; font-size: 13.3333px; font-weight: 400; margin: 0px; text-decoration: none; border-bottom: 0px rgb(86, 89, 94);"></button>
Chat output response:
[System] Cleaned up 1 event(s) and 1 background loop(s).
If you want a silent cleanup without any spam in the text feed, run:
text
/commander:eventcleanup false

โš ๏ธ Error Diagnostics (How it helps you debug)
If your JavaScript contains syntax mistakes or errors out during execution, the script intercepts the crash and formats a helpful error prompt in the game chat.
If you execute broken code, it tells you exactly what went wrong and points to the target source line:
text
/commander:javascript "player.sendMessage('Test'); player.fakeMethod();"
Chat output response:
[Function Error] player.fakeMethod is not a function at line 1
> player.sendMessage('Test'); player.fakeMethod();

 
 

The JavaScript Ingame Team

profile avatar
  • 2
    Followers
  • 16
    Projects
  • 405
    Downloads

More from cript0pandaView all