-
Notifications
You must be signed in to change notification settings - Fork 32
Scripting
Scripting in Punchy is powered by the bevy_mod_js_scripting
plugin. Scripts may be written in either TypeScript or JavaScript and run both on native and in the browser.
We are using Deno's core wrapper around V8, which is the underlying C++ JavaScript engine that Node.js, Deno, and Chrome use.
It doesn't have any of Deno's runtime features, though, such as filesystem or network access. The scripts can only access the ECS game world, which is actually great for running untrusted mods.
It's also worth noting that when running on the web Deno isn't used, but the native JavaScript engine of the browser playing the game is used instead.
Right now bevy_mod_js_scripting
is very work-in-progress, but it's developing nicely. As we (mainly zicklag) work on integrating scripting with Punchy and Jumpy, we’re adding the extra features we need to bevy_mod_js_scripting
while working with @jakobhellermann to figure out the best way to design the scripting API.
At the time of writing we only have two scripts in Punchy: a demo script and the script to implement the Health item. The scripting API is extremely work-in-progress and may change quickly as we try to find the best way to connect Bevy to JavaScript.
Check out the demo_script.ts
and health.ts
scripts to get an idea for what the API is like.
The plan is to move as much of the gameplay code into scripts as possible. For example, the goal is to have all of the items and fighter attacks implemented as scripts, if possible. This has some useful side-effects:
- Gameplay development can be quicker because we don't have to wait for scripts to compile, and they can be hot reloaded while the game is running for instant feedback.
- Implementing the gameplay with scripts makes sure that the scripting interface is powerful enough to use for great mods. It also removes that barrier between modded items and built-in items that can make it feel like mods are stuck using a half-baked, limited API that only lets them change select aspects of the game.
The goal is not to allow scripts to change the game architecture. Most of the game will be written in Rust, but we want to allow scripts to change as much as the gameplay aspects as possible.
- The included
demo_script.ts
has a tutorial-like overview of the scripting API. - The
health.ts
demonstrates how to make a simple item with the scripting API.