Difference between revisions of "Programmable Block"

From Space Engineers Wiki
Jump to: navigation, search
(fixed bug in component list)
(Programming: + Malware's coding guide)
Line 154: Line 154:
 
== Programming ==
 
== Programming ==
 
* [[Programming_Guide/Action_List#Programmable_block|Action List - Programmable block]]
 
* [[Programming_Guide/Action_List#Programmable_block|Action List - Programmable block]]
 +
 +
== External links ==
 +
* Programmable block [https://github.com/malware-dev/MDK-SE/wiki/Quick-Introduction-to-Space-Engineers-Ingame-Scripts coding guide] - Malware's coding guide
  
 
== Update History ==
 
== Update History ==

Revision as of 02:19, 17 July 2019


Programmable Block Icon.png
Large Ship Icon.png
Large Ship / Station
Programmable Block
 
Components
Required

 

 
 
1
 
 
Mass (kg):
0
 
Integrity:
0
 
Build time (seconds):
20
 
Active power consumption (MW):
0.0005
 
Airtight:
No
 
Power Consumer Group:
Utility
 
Dimensions (W x H x D):
1 x 1 x 1
Programmable Block Icon.png
Small Ship Icon.png
Small Ship
Programmable Block
 
Components
Required

 

 
 
1
 
 
Mass (kg):
0
 
Integrity:
0
 
Build time (seconds):
20
 
Active power consumption (MW):
0.0005
 
Airtight:
No
 
Power Consumer Group:
Utility
 
Dimensions (W x H x D):
1 x 1 x 1

Overview

A Programmable Block can be programmed to do different functions, like switching lights and controlling doors. It can also be used by entering the control panel in the Terminal. It has almost unlimited functionality.

Usage

Programmable Block scripts run in a single update (single frame) and any that take too long to complete are aborted. This means it is impossible for a single run of the script to 'wait' on any event. If you want your script to run when something happens, you need to either find a way of getting another block to trigger it at the right time (an 'interrupt-driven' approach via eg. a sensor block), or modify your script to check for a precondition and set up a timer to run it regularly (a 'polling' approach). Depending on what your script is doing, one approach may be the preferred or even the only way to do it.

  • Since Update 01.067 Hotfix 007 each programmable block has a maximum limit of 100,000 characters for any in-game script.

GUI Overview

The programmable block terminal panel screen currently contains two buttons:

Edit – it will open the editor for editing scripts and the ability to save/load scripts from and to disk. Also, you can upload your scripts to workshop and download subscribed scripts.

Run – it will run the script that was remembered in editor. It will run the script only once. However this button is terminal action, so you can attach it to sensor, timer block, and button or add it to toolbar.

Steamworkshop webupload previewfile 360966557 preview.jpg

Details section – In this area the script exception will be shown (if any will occur)

Editor

Steamworkshop webupload previewfile 360966557 preview (1).jpg

Code editor contains these buttons:
  • Help – it will open the help guide inside the game.
  • Check Code – it will check the code for code mistakes and also check if used code isn’t forbidden.
  • Remember & Exit – it will save the code for execution, close editor screen and returns to terminal panel.
  • Remember code – it will save code for execution and leave editor open.
  • Browse Workshop – it will open a window for script management, you can save/load scripts from disk , upload scripts to workshop and download subscribed scripts.
  • Line counter – it shows current line number and total number of lines in code

Browse Workshop

Browse workshop.jpg

This screen is similar to blueprint screen and contains these buttons :
  • Ok – it will load the selected script into the editor and close the screen
  • Cancel – it will close the screen (no changes to code in editor)
  • Details – it will open the "details" screen, where you can see description of script
  • Rename (only for local scripts) – it will rename the selected script, if you try to rename to existing script, the game will ask you if you want to overwrite the existing script.
  • Delete (only for local scripts) – it will ask you if you really want to delete the script, after the confirmation script will be deleted.
  • Create from editor– it will create new script with default name Script_XX it starts with 0 and if the script with the selected name already exists, it will increment the value. E.g. first there will be Script_0 then Script_1 etc…
  • Replace from editor (only for local scripts) – it will replace (after user confirmation) the selected script with script from the editor.
  • Refresh Scripts – will reload the local and subscribed script list

Details (local script)

Details (local script).jpg

This screen will show up when you press details for local script and contains the following buttons:
  • Rename – it will rename the selected script, if you try to rename to existing script, the game will ask if you want to overwrite the existing script.
  • Delete – it will ask you if you want to delete the script, after confirmation script will be deleted.
  • Publish – it will publish the script into workshop and show the workshop page with the script.
  • Browse Workshop – it will open the workshop screen to browse and subscribe scripts.
  • Close – it will close the screen

Details (workshop script)

This screen will show up when you press details for script from workshop and it contains these buttons:

  • Open in Workshop – it will open the current script workshop page.
  • Close – it will close the screen

Media

Programmable Block ProgramBlock01.jpg

Tips

Known Issues

  • Foreach not working at 64- bit:

Problem - Currently using of foreach loop inside script will cause “bad program exception” at some configurations and prevent script from running. We are working of fixing this issue.
Workaround - All our interfaces used in in-game scripting are using lists as collections. Please use For loop for iteration across these lists

  • Lambda functions not working

Problem: Currently lambda functions are not supported, if you use them in script, exception will be thrown and script will not run.
Workaround - Please use method instead of lambda function if possible.

  • User defined static variables and methods not working

Problem - Currently using user defined static members or methods will cause script to throw exception and the script will not run.
Workaround - Please don’t define static methods or variables.

  • User defined variables are not saved

Problem - None of the user defined variables inside script are saved, therefore after loading game they are reset to their default values.
Workaround - We added string variable called "Storage" that will be loaded and saved when the block is loaded and saved.

See Also

Programming

External links

Update History

Update 01.063
  • Programmable Block Introduced