Engine Environment
Minecraft: Bedrock Edition uses its own version of JavaScript, which is based on QuickJS. It uses the ECMAScript module (ESM) system for organizing and loading code, which allows for a more modular and organized approach to writing scripts for the game.
Common problems
- SetTimeout support
What people often run into when starting out with Minecraft Scripting is the problem with timing. The standards for timing code, as you may know, are the setTimeout
and setInterval
functions and their cancel functions.
These standardized methods are used by the frame system where you can set the delay to millisecond precision, but minecraft uses a tick to process changes in the world. That's why these methods are not and will not be available. Minecraft instead use system.runTimeout
and system.runInterval
system methods, first added in version 1.19.70, which delay to the precision of one tick. You can read more about this on Microsoft Docs or Wiki Tutorial
- Eval permission
Not everyone can encounter this problem because the use of eval and Function method for running code in string format is not great.
Some browsers also prohibit the use of these methods, mainly the eval method, as when using eval there is a risk of malicious code which is why it is disabled by default.
To enable these methods that evaluate code, you must add it in the manifest. This capability also adds the usage of the Function()
constructor.
{
"capabilities": ["script_eval"]
}
Support
What is supported
Object
- Standard function constructor for objectsFunction
- Standard function constructor for functionsError
- (EvalError
,RangeError
,ReferenceError
,SyntaxError
,TypeError
,URIError
,InternalError
,AggregateError
) - Classes for error constructionArray
- (Int8Array
,UInt8Array
,Int16Array
,UInt16Array
,Int32Array
,UInt32Array
,Float32Array
,Float64Array
,SharedArrayBuffer
,ArrayBuffer
,UInt8ClampedArray
) Standard function constructor for Array objectsparseInt
,parseFloat
- Standard methods for parsing string to numberisNaN
,isFinite
- Standard methods for checking number typesdecodeURI
,encodeURI
- Standard methods for decoding and encoding URI pathsdecodeURIComponent
,encodeURIComponent
- Standard methods for decoding and encoding URI componentsescape
,unescape
- Non-standard methods! Please use decodeURI/encodeURI if possibleNaN
,Infinity
,undefined
- Standard variables for in-code usage__date_clock
- Built-in QuickJS method for getting current timeNumber
,Boolean
,String
,Symbol
- Standard function constructor for JS primitivesMath
- Standard object having primary math functions, such as trig ratios & powersReflect
- Standard object having built-in methodseval
- Standard method for evaluating string as code. Note that the capability for this must be added to the manifest.globalThis
- Standard object with access to global scoped variablesDate
- Standard function constructor for date instanceRegExp
- Standard function constructor for regex instanceJSON
- Standard object having stringify and parse methods for JSON interactionProxy
- Standard function constructor for build-in proxy handlerMap
,Set
,WeakMap
,WeakSet
- Standard function constructors for data organisation objectsDataView
- Standard function constructor for binary array interactionsPromise
- Standard function constructor for async interactionconsole
- Standard object having base output methods (log
,warn
,error
,info
)
What is not supported
setTimeout
- Standard function for timing code runssetInterval
- Standard function for timing code runs in intervalsclearTimeout
- Standard function for canceling setTimeout runsclearInterval
- Standard function for canceling setInterval runs
Extended Methods We have bunch of additional methods exposed by QuickJS, but do not expect anything game-changing! We do have some additional string methods to wrap string in html formats. For example:
"text".bolt() -> "<b>text<b>"
. These methods are useless and not documented and we are not going to either.