Your First Addon
This guide will run over creating your first addon.
Importing PythonToSW
Before we begin with creating an addon, we need to first import PythonToSW.
from PythonToSW import (
Addon,
CallEnum,
CallbackEnum,
AddonConstants
)There are more things we can import, but these four are the the only things relevant to the guide.
Creating The Addon
As shown in the import code, we imported Addon which is a class representing a PythonToSW addon. To create an addon, we simply create an instance of this class like so:
addon = Addon(
"My Addon",
path = ".",
port = 2500
)This will create an addon which runs on port 2500, and will store addon-related data at . .
Starting The Addon
PythonToSW addons comes with three built-in events, which include:
on_start: Fired when the in-game addon connects to your PythonToSW addon.on_stop: Fired when the in-game addon disconnects from your PythonToSW addon (e.g. game exited).on_tick: Called every tick at a default rate of 32 ticks/s, only if connected. More on this in a future page.
To start the addon, we need to call the .start() method land optionally pass in functions for on_start and on_stop.
You can also do it like so:
Whatever floats your boat!
This will then automatically setup the addon and run a localhost server as you'll see in your terminal.

You'll also notice a .json file gets created at the path you provided for the path argument. This simply contains data for your addon that needs to persist, like request tokens.
Finished
Congratulations, you have created your first addon!
Start up a world in Stormworks and look through your addons, you'll notice an addon with the name (PTS) My Addon (or whatever you named your addon). If you enable it and start up the world, you'll see "(addon name) has connected." in your terminal and all should work!
Last updated
Was this helpful?