Your first mod
The quickest path is atl-build: write a normal Scrap Mechanic mod folder,
put a .wasm file where the Lua script would go, and let the tool turn it into a mod the game
loads.
What you need
Section titled "What you need"clang++with thewasm32-unknown-unknowntarget (any recent LLVM).- The C++ SDK headers (
atl.hppand theatl/folder). - atl-build, a single program for Linux, macOS and Windows.
1. Write the part in C++
Section titled "1. Write the part in C++"#include <atl.hpp>using namespace sm;
class Lamp : public ShapeClass {public: bool client_canInteract(Character) override { gui::interaction("Use", "Toggle"); // [E] Toggle return true; } void client_onInteract(Character, bool pressed) override { if (pressed) network().sendToServer("sv_toggle"); } void sv_toggle(atl::Value, Player sender) { on_ = !on_; interactable().setActive(on_); log::info("{} toggled the lamp at {}", sender.name(), shape().worldPosition()); }private: bool on_ = false;};ATL_CLASS(Lamp).method<&Lamp::sv_toggle>("sv_toggle");2. Compile it to WASM
Section titled "2. Compile it to WASM"clang++ --target=wasm32-unknown-unknown -std=c++20 -O2 -nostdlib -fno-exceptions -fno-rtti \ -fno-threadsafe-statics -Wl,--no-entry -Wl,--gc-sections \ -I path/to/atl-headers -o MyMod/Scripts/lamps.wasm src/lamp.cpp3. Point the part at the class
Section titled "3. Point the part at the class"In your shapeset, give the .wasm file as the script and the class as usual:
{ "partList": [ { "uuid": "4dec7cdb-0d72-44a2-8732-e1da29a55fae", "renderable": "$CONTENT_DATA/Objects/Renderable/lamp.rend", "hull": { "x": 1, "y": 1, "z": 1, "col": "$CONTENT_DATA/Objects/Collision/lamp.obj" }, "scripted": { "filename": "$CONTENT_DATA/Scripts/lamps.wasm", "classname": "Lamp" } } ]}Everything else in MyMod/ (description.json, renderables, inventory text) is written the
same way as for any mod.
4. Build the mod
Section titled "4. Build the mod"atl-build MyMod -o "<Scrap Mechanic>/Mods/MyMod"atl-build packs the module, writes the Lua glue, adds AllTheLanguages to the mod's
dependencies and adds the bootstrap tool. See atl-build for exactly what
it changes.
5. Try it
Section titled "5. Try it"Enable AllTheLanguages and your mod in a world, place the part and press E on it.