Lench Scripter Mod [Besiege v0.42]


Active Member

This mod enables you to control your Besiege machine with Python 2.7/3.0 scripts.
Changing sliders or toggles and triggering actions allows you to create controllers, stabilizers, autopilots or anything you can dream up to guide your machines.

NOTE: This mod requires some basic programming knowledge.

Place your scripts in .../Besiege_Data/Scripts/ directory with .py extension with the same name as machine.

my-machine.bsg -> my-machine.py

They will be ran automatically when simulation starts.
Read the wiki for more information on running scripts.

This script simply controls the speed of an automatic wheel.
When U is held down, the wheel spins with speed 1.
If you press I, spinning direction is inverted.

# get block reference
wheel = Besiege.GetBlock("WHEEL 1")
direction = 1

# set wheel toggle mode
wheel.SetToggleMode("AUTOMATIC", True)

def Update():
""" updates the speed on every frame """
# direction variable is defined globally
global direction

# if U is held down, speed is 1
if Input.GetKey(KeyCode.U):
speed = 1 # set speed to 1 if U is pressed down


speed = 0

# invert direction if I is pressed

if Input.GetKeyDown(KeyCode.I):
direction *= -1

# set wheel speed slider

wheel.SetSliderValue("SPEED", speed * direction)

For more examples, read the tutorials.

Read getting started guides here.
Read full documentation here.

Read about mod integration here.
Requires Spaar's Mod Loader

Previous versions

Source code available on GitHub.
Feedback, suggestions and contributions are very welcome.

See the examples on the workshop.

Join the community Discord chat for help!
Last edited:


Staff member
Nice! Btw, have you joined the modding slack team yet?


Active Member
Hover your mouse over it and press left shift. It will dump it into the console (Ctrl+K).
Every block ID looks like <block name><sequential number>. For rockets, it will be ROCKET 1, ROCKET 2, etc. for all the rockets you have.


Staff member
You might want to consider allowing the use of GUIDS in addition to "ROCKET 1" etc., as the order or amount of rockets could change.
Maybe some "replace all blockID's with GUIDS" button or something, alongside that?


New Member
Is there a concise list somewhere of changes that break compatibility with Rtbwrrr's and Lachcim's mods?

Don't get me wrong BTW, the breaking changes I've noticed so far are certainly good things (position as a vector just makes more sense; dealing with multiple sliders is a must due to Besiege changes; stable block identification was sorely needed). Its just that a list of such changes might take some of the trial and error out of porting existing scripts.
Thanks for this. I only started working on updating mine a couple of days ago, but I don't really know enough C# or Unity at the moment.


New Member
Thanks, that's really useful! I've already started porting my guided bombs (and after it's ported, I should be able to delete quite a lot of code due to new features).

By the way, is there a way to get in-game time? It looks like
advances in real-world time regardless of simulation speed.

It's probably not terribly important now, since there is a way to get block velocity directly, which is the main thing I was using time for before (I had to place spinning objects in game and measure them to calculate time).


Active Member
Good noticing, you are right.

I'm working on a new release that will include a function getScaledTime(), which returns time consistent with timescale slider, and some other nice features.

By the way, you have access to UnityEngine itself, so you can actually just call Time.time to get what you want.


Staff member
If you have access to &quot;Time&quot;, just use Time.deltaTime and add it to a timer.


Staff member
Formatting totally isn't just the .ToString() of it >.> :p


Active Member
Release v0.60: Call block mods public methods!
drum = besiege:getBlockScript("WAR DRUM 1")
time = 0

function onUpdate()
    --- strike drum every second
    time = time + Time.deltaTime
    if time > 1 then
        time = time - 1


Active Member
Unfortunately not. Only modded blocks, loaded by TGYD's Block Loader, who have exposed public methods like the war drum for example. I know Pixali is working on his laser mod to allow you to get laser hit position etc. to script.

The only way that I know of activating cannons and such is by simulating key presses, and that is tricky.