Programmable Block

From Space Engineers Wiki
Jump to navigation Jump to search
Programmable Block
Icon Block Programmable Block.png

Category: Functional
Function: executes C# scripts

Fits small grid
Mass: 138.4 kg
Power: - 0.0005 MW
PCU: 100
Size: 1x1x1
Time to Build: 8 sec

Fits large grid
Mass: 534.4 kg
Power: - 0.0005 MW
PCU: 100
Size: 1x1x1
Time to Build: 20 sec

Data Controls: [edit] [purge] (?)

Icon Block Programmable Block.png Programmable Blocks (short: PB) can execute C# scripts in game to automatically perform a multitude of game functions. If a Timer Block or Sensor can't handle your task, a PB likely can. For a simpler, more user-friendly alternative, see also Event Controller. The block’s secondary use is decorative.

Usage

No mods required. You either subscribe to Scripts on the Workshop or write them yourself. The script can run in a loop or can be triggered by a game event.

Requirements

Before you can use Icon Block Programmable Block.png Programmable Blocks, check the following requirements:

  • Scripts run only on PC (Steam, Microsoft Store) and Dedicated Servers, not on consoles.
  • Scripts run only if Experimental mode is enabled in the Options.
  • Scripts run only if in-game scripts are enabled in the World Settings.
  • PBs run scripts only while they have power in game.

To get suitable scripts, you must subscribe to scripts from the Workshop or know how to write C# scripts using the Space Engineers API.

Important: Read up on the scripts that you subscribe to on the workshop, they come with different instructions, such as, "edit certain lines in the script", "enter certain arguments", "rename certain blocks in the grid", or "enter certain keywords as custom data", and similar.

Warning : Many multiplayer server admins will punish or outright ban you for running performance-intensive scripts! Be considerate of the other players on the server when running scripts!

What can scripts do?

For comparison, Timer Blocks can only switch blocks on and off (such as lights), and increase and decrease a few values (such as wheel suspension height, rotor/piston/hinge reverse, or thruster override) in fixed intervals. In contrast, PB scripts can read, calculate, and write any value. For example, you could dim the light colour from white to red, or turn a rotor/piston/hinge to any position, or set the thruster to any speed.

Sensors can only detect proximity, whereas PB scripts can read any state information of a block or grid and react to it. For example, the script can look at the content of inventories, wheel steering settings, damage state, positions, speed, ownership, ...

Event Controllers lie inbetween Timers/Sensors and PBs: They are easier to use than Scripts, but only support a subset of in-game Script functions.

In simpler use cases, you may use in-game scripts to change light color patterns, or to control a crane. In advanced use cases, you may want to direct auto-mining drones, fly with vector-thrust, control wheel propulsion on subgrids, display the ship’s damage status on a floor plan, detail current power usage, auto-manage inventories or production, get a radar view of your interplanetary surroundings, draw a planetary map, activate timer blocks remotely, and much more…!

Tip: Go to the Steam Workshop and filter the search by “last year” and (important) select Type: InGameScript to browse fantastic scripts shared by the community!

How to enter a script

Right-click (or press F key while facing) the PB's interface in-world to interact with the block directly, or open the grid’s Terminal as usual.

  1. On the Control Panel Screen, click Edit to open the script editor.
    It will open with an empty default script that has basic hooks for you to fill in.
  2. Enter your script in one of these ways:
    • Either click Browse Scripts, select a subscribed script from the Workshop, then click Copy to Editor.
    • Or type the script manually — or rather, paste it from your Visual Studio application.
  3. If the description asks you to customise some lines, do that now.
  4. Click Check Code and a dialog will say "Compilation successful" (or give an error message about what you'll need to fix). Click OK.
  5. Click OK to save the script.
  6. If you are using a script that needs custom data:
    1. Click Custom Data.
    2. Enter your values and click OK.
    3. Click Recompile.
  7. Optional/If applicable: Enter an argument in the Argument field.
  8. Click Run.

You will see helpful info in the bottom right corner.

Some scripts run in a loop. For others, you must set up a trigger (button, sensor, timer) that executes the Run action.

How to start the script

There are many ways to start a script, some require you to build additional blocks on the grid.

Refer to the script's workshop page description for proper usage.

The following triggers are not mutually exclusive, you can activate the same PB in many ways:

  • Scripts can run themselves if programmed that way.
  • Manually using the Run button on the Control Panel Screen.
  • Assign the PB Run action to a Toolbar slot.
  • Assign the PB Run action to any Button Panel so players can push the buttons in game.
  • If the tasks depends on the proximity of someone/something, use a Sensor to trigger the PB Run action.
  • If you want to run it together with other actions, set up a Timer Block to trigger the PB Run action and the others.
  • If you have a drone or shuttle that is controlled by the Remote Control Autopilot, any waypoint can trigger the PB Run action.

Troubleshooting

  • If the Programmable Block editor is stuck and you cannot close the window, nor click any buttons, click both mouse buttons to get unstuck.[1]
  • If you don't see an Edit button, save and close the game, open its Advanced World Settings, and enable In-Game Scripts.
  • If you have made any changes that affect the script, such as renaming blocks or changing Custom Data, always click Recompile.

When you click Help inside the Code editor, it will open an old guide on Steam that has old-looking screenshots — don't let that scare you off scripting. Bookmark and read this new in-game Script guide by Malware instead: Scripting.

When NOT to use PBs?

  • A PB obviously only helps you accomplish your task if a SE API exists that performs the tasks that you want. Also, you or somebody must write the script. Don't expect the PB itself to help you with the programming.
  • If you want to steer a drone ship, consider first whether the standard Autopilot, Event Controller, or Automaton can do what you need in a simpler way.
  • Badly written scripts are very performance intensive when they loop unnecessarily fast. If millisecond speed and precise calculation and setting of values is not essential, PBs are overkill, use other less resource-heavy methods first.
  • On multiplayer servers, an admin may disallow the use of all or certain scripts, so don’t rely on them too much outside your singleplayer games.

Gallery

The small-grid variant of a PB looks like a wall-mounted laptop. Small battery in the background.

Construction

You must build one Programmable block per script. They are cheap to build but take up 1x1x1 space, both on large and small grids.

The large-grid block has mount points on the bottom side. It has one side with a decorative screen interface that you may want to keep accessible, but that's not a requirement. The small grid block has one mount point on the backside.

Its LCD surfaces are configurable: Unless the script itself uses them to display its status, you can put any content on them, including built-in LCD scripts or text or images.

Visually, the large grid block looks like a fridge-sized mainframe with a built-in LCD display and keyboard. The small-grid variant looks like a small wall-mounted tablet with a small keyboard hanging under it. You can use PBs decoratively without loading an actual script, for example, if you build a chair in front of the large-grid variant, it looks like a workstation or bridge officer’s seat.

Recipe

Icon Block Programmable Block.png Programmable Block
ComponentLarge Ship/Station
Required
Large Ship/Station
Optional
Small Ship
Required
Small Ship
Optional
Icon Item Steel Plate.png Steel Plate111011
Icon Item Motor.png Motor11
Icon Item Large Steel Tube.png Large Steel Tube22
Icon Item Display.png Display11
Icon Item Construction Comp..png Construction Comp.42
Icon Item Computer.png Computer22


Functional Blocks

References