Jump to content

[Lua] [Example] Printing max engine thrust

Recommended Posts




This is a short script that prints base max thrust of linked engines. It can serve as an example, and may also be used to detect which engines do not have a technician buff applied to them.



  1. Place a programming board.
  2. Link up to 10 engines to the programming board.
  3. In the Lua editor (right-click, "Advanced", "Edit Lua code") create a unit start() event handler with this code:
    -- detect linked engines
    local engines = {}
    for key, value in pairs(unit) do
      if type(value) == "table" and type(value.export) == "table" then -- `value` is an element and `key` is the slot name
        if value.getThrust and value.getMaxThrust then -- `value` is an engine
          engines[#engines + 1] = value
    -- get engine names
    local engineNames = {}
    for _, engine in ipairs(engines) do
      -- engine name is available in its widget data
      -- for other elements `core.getElementNameById` would have to be used instead
      local dataJson = engine.getData()
      local data = json.decode(dataJson)
      engineNames[engine] = data.name or "???"
    -- sort engines by name
    table.sort(engines, function (engine1, engine2)
      return engineNames[engine1] < engineNames[engine2]
    -- print engines and their base max thrust
    system.print("Linked engines: " .. #engines)
    for _, engine in ipairs(engines) do
      local name = engineNames[engine]
      local maxThrustBase = engine.getMaxThrustBase()
      system.print(string.format("%s: %.0f N", name, maxThrustBase))


  4. Click "Apply" in the Lua editor, exit build mode and activate the programming board. You should see base max thrust printed in the Lua chat tab.


Change log

2020-09-13. Posted the first version (tested in r0.21.5).

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...