Skip to content

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.

  • clang++ with the wasm32-unknown-unknown target (any recent LLVM).
  • The C++ SDK headers (atl.hpp and the atl/ folder).
  • atl-build, a single program for Linux, macOS and Windows.
src/lamp.cpp
#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");
Terminal window
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.cpp

In your shapeset, give the .wasm file as the script and the class as usual:

MyMod/Objects/Database/ShapeSets/lamps.shapeset
{
"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.

Terminal window
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.

Enable AllTheLanguages and your mod in a world, place the part and press E on it.