Page Contents

The sequence editor is an easy to use tool for automating FarmBot operations. However, advanced users who are familiar with computer programming concepts may opt for a more advanced interface. For these users, we provide several methods to insert Lua code fragments directly into sequences:

Lua commands

Using a Lua command is the most straightforward and universal way to use Lua in your sequences. With the Lua command, you can execute up to 3000 characters worth of code - enough to operate FarmBot’s motors, sensors, peripherals, and camera, and even use 3rd party APIs.

Assertion commands

The Assertion command also allows for long-form Lua code execution as well as the ability to execute a subsequence or abort execution depending on the return. (Learn more).

Formulas

You can also execute Lua by using the formula option in a Move command’s OVERRIDE or X, Y, Z input fields. This option is generally best for short-form code that only deals with positioning.

A Note About Long-Running Lua Scripts

Lua, like many scripting languages, has automatic garbage collection. Although the FarmBot Lua runtime does support garbage collection, it will never run the garbage collector automatically. Determining the appropriate time to run garbage collection is the end user’s responsibility, which is quite different from most Lua environments.

If you have a long-running Lua script that appears to slow down over time, or you find that FarmBot OS runs out of memory while a script runs, this most likely means that you need to run the garbage collector.

End users can trigger a garbage collector sweep by running collectgarbage(). Most users do not need to do this, and this advice only applies to long-running and memory-intensive Lua scripts.

What’s next?