Space Engineers

Space Engineers

Not enough ratings
Sequencer v2 Programming Guide
By Krypt and 1 collaborators
Guide for Sequencer v2 Script
   
Award
Favorite
Favorited
Unfavorite
Features
This script was designed as a replacement for multiple chained timer blocks, or multiple timer blocks in general. All capabilities and limitations are caused by this intended use.

Features:
- multiple scripts executed by one block
- simultaneous execution of multiple scripts
- ability to:
- start actions
- change properties
- run another programmable block
- change text on lcd screen
- send remote message
- wait for time period with sub second precision
- transparent save/load handling (you don't need to worry about state reset on game load)
- player input handling with Digi's Control Module


Workshop URL: https://steamcommunity.com/sharedfiles/filedetails/?id=1085402845
Installation
- Install a Programmable block
- Load Sequencer v2 script into it
- Put your custom code into Custom Data of that block
Script arguments
Run arguments can be assigned to "run" action in buttons, sensors, or used as "default argument" in terminal interface.
There is list of available arguments:

start [method]
Starts a method if it's not started yet.
method (optional): method name. If the method name is not available, the default method will be started.
Examples:
start main start mymethod start

stop [method]
Stops method execution if it's currently executing.
method (optional): method name. If the method name is not available, the default method will be stopped.
Examples:
stop main stop mymethod stop

exec /command or just /command
Executes argument as a command.
command: Any command except for method names. Can contain multiple commands but no method names.
Examples:
exec /echo Example exec /echo "this works" exec /wait 2 /echo "this displays after 2 seconds" /wait 2 /echo "so does this"

parse
Reloads code from "Custom Data". Does not reset variables or stop executing methods. If a method is executing it will be updated after its termination. That's useful if your Sequencer script is currently executing multiple methods on your station/ship and you want to modify only one of them.

reset
Does a full reset of the script: the state of the script will be like it was just loaded into the PB.

status
Outputs diagnostic information.
Language syntax
@method-name
Defines a name for the method. You execute a method by running the script with the argument "start method-name". If there is no method name specified for a block of code, you execute that block using only "start" as the script argument.
Example:
@firstmethod /echo Hi.

#comment
Comment until the end of a line.
Example:
/wait 2 # everything after the # doesn't change what the code does

/command arguments
Command with arguments. Tuples can be used here in place of several arguments.

There are three ways to define arguments:
1)
argument
Argument without any special characters or whitespace.
Example:
/echo Hi.

2)
"argument"
Argument with special characters or whitespace inside. Escaped sequences like \n or \u263A are supported. See "Escaped sequences" section for more details.
Example:
/echo "Hello galaxy!"

3)
:argument
Argument in IRQ style. Anything after ':' until end of string is argument
Remark: Be accurate with SE text editor: it inserts extra spaces at ends on strings. If command requires exact value - it can be not recognized.
Example:
/echo :Greetings, Earthlings. We come in peace.

$tuple argument1 argument2 argument3 ...
tuple - name of the tuple.
A tuple is basically a group of arguments in this context.
NOTE: The syntax will probably be modified in a future version to make it compatible with variables. In the current version of the script, tuples cannot be modified during runtime.

/command %tuple argumentN ...
Tuple usage. Inserts the tuple's content as command arguments. Can be used with other arguments or tuples.

Example. To execute this code snippet, you copy and paste it into the "Custom Data" field of the Programmable Block, then load the code by running the PB with the argument "parse" and then "start generalkenobi".
@generalkenobi /echo "Hello there!" # this works because "Hello there!" is enclosed in quotes # /echo Hello there! wouldn't work because the "Hello there!" is not contained in quotes and it would be seen as two arguments by the Sequencer script /wait 2 # wait two seconds /echo "General Kenobi!" /wait 1 # wait one second /echo :You are a bold one! # everything after the : is seen as one single argument
Escape sequences
It mostly follows C string escape sequences list:

Escape Sequence
Description
\n
New Line
\r
Carriage Return
\t
Tab
\'
'
\"
"
\?
?
\\
\
\uXXXX
X is a hexadecimal digit: UTF-16 encoded character
\UXXXXXXXX
X is a hexadecimal digit: UTF-32 encoded character
Available commands
There and below stuff inside [] is optional

Ingame API related commands

/run [filter_type] filter argument
Starts all matching programmable blocks with argument "argument"
argument - Main method of started PB will called with this value

Called PB uses consumes instructions of caller. Also, if called block fill hit instruction limit
Sequenced script will stopped instead. If it happens you can try to install timer and make it to start PB. To start Timer use "/action Timer TriggerNow"


/action [filter_type] filter action
Starts action of all found blocks if blocks supports this action.
action - action name

You can list available actions using /listactions command


/set [filter_type] filter property value
Set property of all found blocks if blocks have this property.
property - property id
value - property value

List properties are supported. You can use Keen's magic numbers or readable values for thos properties. Also you can list available properties using /listprops command


/text [filter_type] filter [surface_index] [append] text
Modifies text displayed on text surface (text panel block or any text panel on another block)
surface_index - index of text surface. default is 0
append - flag, if true - text will appended, if false - text will replaced. Default is false.
text - text to be displayed/appended


/transmit [filter_type] filter [target] value
Transmit message using available Antenas or Laser Antenas
target - list of MyTransmitTarget values, separated by '|', ',' or space (in case of space you need to use quotes for whole argument). Default is "Default". Which actually is "Owned|Ally"
value - value to be transmitted

If transmits laser antena [target] value will ignored


/data [filter_type] filter [append] [permission] text
Modifies Custom Data of found blocks.
Be cautious with this command, it can be destructive because it can override configurations.
append - append text to instead of replacing. Default is false.
permission - write prermission, by default Sequencer refuses to write Custom Data of programmable blocks
text - new/appended text

Permissions:
DontAllowPB - don't modify PB values
AllowPB - modify any PB but not itself
AllowSelf - modify any PB including itself


Program flow related commands

/wait seconds
Waits for "seconds" number of seconds
seconds - seconds to wait

Time delay is scaled. It uses ingame time intervals.


/waitticks ticks
Waits for "ticks" number of ticks
ticks - ticksto wait

Tick is 1/60 of second. Also tick is minimal ingame interval.
Time delay is scaled. It uses ingame time intervals.


/repeat
repeats method from begin.


/setvar variable intvalue
sets value to variable
variable - varuable name
intvalue - new integer value


/switch variable method1 method2 ...
selects method to execute and starts it
variable - variable which stores index of method in list
method1 method2 ... - list of methods, can be any number


Runtime manipulation commands

/start [method]
Starts existing method
method - method name


/stop [method]
Stops method execution
method - method name


/load [[code]]
Pastes code and appends methods to available methods list.
It will be available until script reset and will persist between game sessions
code - code to load


/unload [method]
Unloads method from memory (loaded earlier or stored in user script)
method - method name


Player input

Commands from this block are requare Digi's Control Module to work.
Digi's Control Module user guide: https://steamcommunity.com/sharedfiles/filedetails/?id=656456032


/addinput input [event] method
Registers new input event. Multiple methods can be added for same input
input - input name (see availanle inputs of Control Module)
event - input events, default is "press"
method - method which will be strted then event triggered

/removeinput input [event] [method]
Removes registered input event.
input - input name (see availanle inputs of Control Module)
event - input event, all events if not specified
method - method, all methods if not specified

Available events:
press - key pressed
release - key released

/clearinputs
Removes all registered input events.

/setCMfilter cm_filter
Set Control Module's cockpit name filter. (see Control Module manual)


User script debug helpers

/echo [text]
Outputs text into Sequencer's output
text - text to output


/loglevel [category] [value]
gets/sets level of details for script debug output.
category - name of the category or "all" keyword
Available categories:
sch - scheduller info: script performance related info
prs - userscript parser: usersctipt syntax errors and inconsistencies
gen - general: commands processing
exe - runtime: userscript execution related info
imp - commands: userscript commands related info
tmr - timer: script's timer related info
cmh - Digi's Control Module handler info
all - keyword to refer all categories at once

value - new loglevel for selected category in range 0..3. Default is 2.

To read current loglevel use command without parameters or only with categoty name:
/loglevel
/loglevel all

To write new loglevel run command with 2 arguments
/loglevel all 1

Probably in future I will move this command into Siquencer commands


/listprops [filter_type] filter
List all properties of the found blocks


/listactions [filter_type] filter
List all actions of the found blocks
Filter Types
Match
Select all blocks with exact name

Contains
Select all blocks containing substring in its name

Head
Select all blocks which name is statring with given string

Group
Select all blocks from group with given name

Type
Attempt to found any blocks matching type filter
filter format:
[Type|]Subtype
18 Comments
Babbayega Jul 26, 2019 @ 1:30pm 
would you be willing to assist with a sequencer setup using the base blueprint below? I am also interested in a reverse or recovery option to stop drilling and return. I was going to tinker with it myself, but i am also running up against a language translation issue. I asked the author for the translation part earlier. just no response yet.

https://steamcommunity.com/sharedfiles/filedetails/?id=1775703050&searchtext=deep+core
Babbayega Feb 18, 2019 @ 4:30pm 
was keeping the solar array example, but making a new drill arm one. so names should be good.
Krypt  [author] Feb 18, 2019 @ 4:21pm 
But you, probably, mean different kind of issues:
> as long as names and all are kept unique?
Yes, it should work. If script founds multiple blocks it applies command to all found blocks. "/run" is not an exception, it will run all found blocks.
Krypt  [author] Feb 18, 2019 @ 4:07pm 
Short answer:
I never experiensed any troubles outside of my tests.

Long answer:
- If called PB fall into "too complex exception" caller (Sequencer PB) will be stopped instead.
- Caller will consume Sequencer's intructions instead of its own, but Sequencer can deal with it. In worst case it will continue execution in next frame.

if multiple consequent calls causing "too complex exception" you can try to insert "/waitticks 1" between calls or, well, use a timer to call troubled PB (good written scripts should not cause this issue)
Babbayega Feb 18, 2019 @ 3:03pm 
any issues with two program blocks running the sequencer. as long as names and all are kept unique?
Krypt  [author] Feb 16, 2019 @ 3:27pm 
Unforunatelly, variables are very limited in this version. only 2 related commands are /setvar to set variable and /switch to select execution branch (variable used as index)

Probably you need take a look at "Easy Automation 2". It have different set of features and declares to have math methods: https://steamcommunity.com/sharedfiles/filedetails/?id=694296356

Diego Feb 16, 2019 @ 1:10pm 
im working on a little Connector which includes a Rotor and Hinge and with a Rotor Script.
My Problem is, i dont really understand the variable option.

My Methods are:

@TruckConUp
/run "PB - Rotor Script" "R+,Rotor Truck Connection,5,0.5"
/run "PB - Rotor Script" "R-,Hinge Truck Connection,5,0.5"

@TruckConDown
/run "PB - Rotor Script" "R-,Rotor Truck Connection,5,0.5"
/run "PB - Rotor Script" "R+,Hinge Truck Connection,5,0.5"

What i would need is to set the first 5 in the arg to be a var and i need to increase/decrease it every time the method runs by 5. Is it possible with your script?
Krypt  [author] Feb 16, 2019 @ 12:33pm 
There it is:

@switch_vtol

%vtol_thrust contains "(vtol thrust)"
%vtol_rotors group "vtol rotors"
%vtol_merges match "Merge Block (vtol base)"
%vtol_pistons head "Piston (vtol"
%vtol_lights contains "(merge light)"

/set $vtol_lights Color Red
/set $vtol_lights "Blink Interval" 1
/set $vtol_lights "Blink Lenght" 3

/set $vtol_pistons "Force weld" False
/action $vtol_rotors Attach
/wait 0.3
/action $vtol_thrust OnOff_Off
/action $vtol_merges OnOff_Off
/action $vtol_pistons Extend
/wait 1
/action $vtol_rotors Reverse
/wait 4
/action $vtol_merges OnOff_On
/action $vtol_pistons Retract
/wait 4
/action $vtol_rotors Detach
/set $vtol_pistons "Force weld" True
/action $vtol_thrust OnOff_On
/set $vtol_lights Color White
/set $vtol_lights "Blink Interval" 0
Krypt  [author] Feb 16, 2019 @ 12:30pm 
https://steamcommunity.com/sharedfiles/filedetails/?id=1085533957
This is an example blueprint. Sequencer 2 used for vtol, airlock, and some minor stuff

You need take a look at vtol sequence
Babbayega Feb 16, 2019 @ 12:02pm 
are there examples of this script i could look at? for example, i have a series of timer blocks to handle ten stages of a drill tower, ten sets of pistons. then three timer blocks that retract at a faster rate. i was looking for a way to minimize the complexity.