Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Scripting Reference

This part of the book covers the user-facing API of the scripting languages supported by BMS. This will be where you will want to forward your script users to get started with scripting in BMS.

If you are a modder, welcome! 👋 Apologies for the Rust-centricity of this guide, we are working on it!

Globals

Scripts have only a few builtin globals:

  • import_namespace(namespace): returns the types and functions of a namespace
  • export_namespace(namespace, name, callback): see Exporting functions
  • register_callback(label, function): registers a function as a callback handler

Everything else is imported. world is a static reference to the world, with all sorts of functions available: import_namespace("bms").world. BMS’ own functions are in bms, i.e. bms.current_entity() (the entity the script is attached to, or nil) and bms.current_script() (the script’s handle):

local bms = import_namespace("bms")
print(bms.current_entity())

In this section

PageCovers
NamespacesImporting types, script defined components and events, exporting functions
ReferencesWhat script values point at, assets and handles
Core Callbackson_script_loaded, on_script_unloaded, on_script_reloaded
Constructing Arbitrary TypesType.new, enums and bms.construct
Calling Other Scriptsbms.run_script_callback and bms.queue_script_callback
Events and MessagesSending and observing Bevy events and messages
BundlesInserting and spawning bundles
Core BindingsEvery type and function available to scripts