Space Engineers

Space Engineers

Not enough ratings
PLC-OS Example Codes
By Twotwinbrothers and 1 collaborators
Example Codes for PLC-OS
   
Award
Favorite
Favorited
Unfavorite
Digital Clock (Real time/date)
Whit this code you can place a Clock on your screen

For this element i defided de surface(in this case "Screen 0").
4 spaces horizontal en 20 spaces vertical, the object has a height of 10|1 en witdh of 2|1.
This way you can position it horizontaly on left(4|1) , Center (4|2) or right (4|3) on the screen.
The clock is now on the top of the screen, if you want it on the bottum you chance 20|1 to 20|19. 20|10 is center.

The command line we use:

input,screenname,memory,X,Y,Shape,H,B,°, text,Size,Name,type, , , ,

screenname
screen 0,
screen the element is on
memory
,
nothing to write to Memory
X
4|2,
X position
Y
20|1,
Y position
Shape
SquareFilled
is the shape/sprite of the opject
H
10|1,
Height of object
W
2|1,
Width of object
°
0,
orientation
Text
,
no text [space]
Size
0.8|75|100|255
text size and color in RGB
Name
,
name of the block, no block just use a space
type
time|HH:mm:ss,
type
, ,
no further arguments, needs to be there.

in type we can tel how the time/date is shown

HH
hour
mm
minute
ss
seconds
dd
day nr
ddd
day name
MM
month nr
MMM
month name
yy
Year last 2 nr
yyyy
year full

// digital Clock input,Screen 0, ,4|2,20|1,SquareFilled,10|1,2|1,0, ,0.8|75|100|255, ,time|HH:mm:ss, , ,
On/Off button for Blocks a specific tag
Whit this code you turn blocks whit the same Tag in its name on and of whit Q en E


To add a word to every blocks name in a group you can use this code: remember?

add group,[shipOn],Shipparts

In this case you give every block in group "Shipparts" the tag [shipOn] in there name.


Whit the next code you place an button in the shape of an on/off symbol on "screen 0". Whit the output you make a request and whit input you request info back. So you know what the button has done.
// on/off group button output,screen 0, ,12|9,9|2,off,20,20,0, ,0.7,[shipOn],term,OnOff_On, term,OnOff_Off, , input,screen 0, ,12|9,9|2,off,20,20,0,##<#>,0.4,[shipOn],term , , ,

If you have your cunsor on the symbol and you press "Q" it turns every block whit the Tag in it name "[shipOn]" ON. The button in now green.
And if you have your cunsor on the symbol and you press "E" it turns every block whit the Tag in it name "[shipOn]" OFF, The button in now grey again.

Gauges and Horizon
In this example we want to get info to display in the form of gauges, so we use the Input line whit te sprites "gauges". In this case i'll give it a fix size, otherwise it's hard to get a nice circle.

"speed |" whit de value in m/s wil be writen to the memory, en shown on the gauges.

//speed gauge input,Screen 0, ,2|1,2|1,gauges 1-,90,90,0,#<#>#m/s,0.5|255|255|255,speed | ,speed |000.00|(m/s), , ,

The Next code Add a Horizon to your screen.

// Horizon input,Screen 0, ,2|1,2|1, ,45,45,0, ,0.4, ,hor <N> <A>, , , ,
hor = type
<N> = shows Planet gravity in text
<A> = shows Atificial gravity in text
Altitute
Show an altitute, this works only on planets

// Altitute input,Screen 0, ,2|1,4|3,SquareFilled,40,35,0,alt,0.5,alt | ,alt|00000|(m)|1, , ,
Weapons
in this example i show info about a Gun whits has "[GunL]" in it name.


//button on/off "Q" and shoot Once "E" output,Screen 0, ,12|1,8|5,gun,4|3,6|1,0, ,0.4,[GunL],term,OnOff,term ,ShootOnce //display if gun is on (green) or off (grey) and shoot (blue) input,Screen 0, ,12|1,8|5,gun,4|3,6|1,0, ,0.4,[GunL],gun, , // amount of cardrige in the gun shown whit a Bar input,Screen 0, ,12|3,8|5,bar|4|0,4|3,6|1,0,####<%>,0.5|0|0|0,[GunL],cargo , , ,

in this example i show info about a Rocket Launcher whits has "[Rocket]" in it name.

//button on/off "Q" and shoot Once "E" output,Screen 0, ,12|1,8|5,rock,4|3,6|1,0, ,0.4,[Rocket],term,OnOff,term ,ShootOnce //display if gun is on (green) or off (grey) and shoot (blue) input,Screen 0, ,12|1,8|5,rock,4|3,6|1,0, ,0.4,[Rocket]],gun, , // amount of cardrige in the gun shown whit a Bar input,Screen 0, ,12|3,8|5,bar|4|0,4|3,6|1,0,####<%>,0.5|0|0|0,[Rocket]],cargo , , ,
Tanks
The next code gives a bar that shows the volume of the tank block whit "Tank 1" in it name
When you put the cunsor on the bar and press "Q" it wil turn the block On or Off en whit "E" its turn stockpile of the tank block On Or Off.

output,Screen 0, ,16|1,20|8,SquareFilled,4|1,8|1,0, ,0.4,Tank 1,term,OnOff,term ,Stockpile, input,Screen 0, ,16|1,20|8,bar|0|100 ,4|1,8|1,0,####<%>,0.4|0|0|0,Tank 1,tank<%> , , ,
Battery bar
This code wil show a Bar , we use a different sprite for the bar
if you put the cunsor on the bar en press Q it turn the block whit "battery 1" in its name On or Off. if you press "E" it toggle the block on Recharge, Discharge, or Auto.
// Battery Bar of "Battery 1" Block output,Screen 0, ,16|1,20|15,SquareFilled,4|1,8|1,0, ,0.4,Battery 1,term,OnOff,bat , input,Screen 0, ,16|1,20|15,bar|0|100 ,4|1,8|1,0,####<%>,0.4|0|0|0,Battery 1,bat<%> , , ,
Connector
// connector on/off button output,Screen 0, ,16|2,20|1,conn,20,20,0, ,0.5,Connector,term,OnOff,conn, , input,Screen 0, ,16|2,20|1,conn,20,20,0,##<#>,0.5,CO |Connector,conn , , ,

(note: We use here type "conn" don't use type "term" whit actions "Lock" , "Unlock" or "SwitchLock")

In the input line in argument part called "name'' we have created a memory item called "CO "
we can use this for auto stockpile our tanks, shown in the example below.

//auto stockpile Tanks if connector is connected output,Screen 0,CO Connected,12|10,9|4, ,20,20,0, ,0.7,Tank,term <auto>,Stockpile_On, , , output,Screen 0,CO Off,12|10,9|4, ,20,20,0, ,0.7,Tank,term <auto>,Stockpile_Off, , ,

Cargo (inventory list)
This code show a Bar of how full de "container 1" is in percentage

input,Screen 0, ,12|1,8|5,bar|0|100 ,4|3,6|1,0,<cur>####<%>,0.4|0|0|0,Container 1,cargo , , , ,

input,Screen 0, ,12|9,8|5,bar|0|100 LI ,4|3,6|1,0,<cur>####<%>,0.4|0|0|0,H2/O2 Generator 1,cargo , , , ,
Note: Whit "bar LI" the bar wil become red wen de value is below 10%
inv (get inventory slot)
You can show what in de the Cargo container whit the next code, per cargo slot

//inventory Cargo container whit "[Cargo]" in its name 1 compartment
input,Screen 0,C1 P1,8|1,4|1,SquareFilled,4|1,4|1,0,###<#>,0.6,[Cargo],inv<item> | 0 , , , ,

inv<item> | 0 is the first slot of the Cargo container whit "[Cargo]" in its name.
inv<item> | 1 would be the second, and so on.

In the next example we have 2 cargo container, the first 4 slots can be shown of each container.
//inventory "Cargo 1" container whit 4 compartments input,Screen 0,C1 P1,8|1,4|1,SquareFilled,4|1,4|1,0,###<#>,0.6,Cargo 1,inv<item> | 0 , , , , input,Screen 0,C1 P1,8|3,4|1,SquareFilled,4|1,4|1,0,###<#>,0.6,Cargo 1,inv<item> | 1 , , , , input,Screen 0,C1 P1,8|5,4|1,SquareFilled,4|1,4|1,0,###<#>,0.6,Cargo 1,inv<item> | 2 , , , , input,Screen 0,C1 P1,8|7,4|1,SquareFilled,4|1,4|1,0,###<#>,0.6,Cargo 1,inv<item> | 3 , , , , //inventory "Cargo 2" container whit 4 compartments input,Screen 0,C1 P2,8|1,4|3,SquareFilled,4|1,4|1,0,###<#>,0.6,Cargo 2,inv<item> | 0 , , , , input,Screen 0,C1 P2,8|3,4|3,SquareFilled,4|1,4|1,0,###<#>,0.6,Cargo 2,inv<item> | 1 , , , , input,Screen 0,C1 P2,8|5,4|3,SquareFilled,4|1,4|1,0,###<#>,0.6,Cargo 2,inv<item> | 2 , , , , input,Screen 0,C1 P2,8|7,4|3,SquareFilled,4|1,4|1,0,###<#>,0.6,Cargo 2,inv<item> | 3 , , , ,

Music Player (jukebox only SE Songs)
this will show a music player on the screen, note: you need a sound block with "sound" in it name
// music player control buttons output,Screen3, ,12|1,10|3,TriangleFilled,6|1,6|1,270, P,1.2,sound,sound,prev, , output,Screen3, ,12|3,10|3,TriangleFilled,6|1,6|1,90,N ,1.2,sound,sound,next, , output,Screen3, ,12|5,10|3,Triangle,6|1,6|1,90, ,0.6,sound,sound,play, , output,Screen3, ,12|7,10|3,SquareSimple,6|1,6|1,90, ,0.8,sound,sound,stop, , output,Screen3, ,12|9,10|3,TriangleFilled,6|1,6|1,270, -,1.2,sound,sound,-, , output,Screen3, ,12|11,10|3,TriangleFilled,6|1,6|1,90,+ ,1.2,sound,sound,+, , // Music player display en On/Off button output,Screen3, ,2|1,10|6,SquareFilled,10|3,1|1,0, ,0.7,sound,term,OnOff, , input,Screen3, ,2|1,10|6,SquareFilled ,10|3,1|1,0, ,0.8|255|255|255,sound,term, , , , , input,Screen3, ,2|1,10|6, ,10|2,1|1,0,Vol <vol>#Track<music>,0.8,sound,sound <vol> <music>, , , , , // music player present buttons output,Screen3, ,20|1,20|17,SquareFilled,10|1,10|1,0,1,0.7,sound,sound,MusCalm_01,sound ,del, output,Screen3, ,20|3,20|17,SquareFilled,10|1,10|1,0,2,0.7,sound,sound,MusCalm_06,sound ,del, output,Screen3, ,20|5,20|17,SquareFilled,10|1,10|1,0,0,3,0.7,sound,sound,set 3,sound ,del, output,Screen3, ,20|7,20|17,SquareFilled,10|1,10|1,0,4,0.7,sound,sound,MusPlanet_01,sound ,del, output,Screen3, ,20|9,20|17,SquareFilled,10|1,10|1,0, 5 ,0.7,sound,sound,MusBuild_01,sound ,del, output,Screen3, ,20|11,20|17,SquareFilled,10|1,10|1,0,6,0.7,sound,sound,MusAlien_05,sound,del, output,Screen3, ,20|13,20|17,SquareFilled,10|1,10|1,0,7,0.7,sound,sound,set 7,sound ,del, output,Screen3, ,20|15,20|17,SquareFilled,10|1,10|1,0, 8 ,0.7,sound,sound,set 8,sound ,del, output,Screen3, ,20|17,20|17,SquareFilled,10|1,10|1,0, 9 ,0.7,sound,sound,set 9,sound ,del, output,Screen3, ,20|19,20|17,SquareFilled,10|1,10|1,0, 10 ,0.,sound,sound,|MusFun,sound ,del,
the contol button work whit "Q"

The present buttons you can add a music number to a present 1-10 with "Q". Press "Q" you can sellect the preset number. whit "E" you delete the preset music number

unfortunately you can't get song time or if the music stop playing by the programmable block. So if the music stop playing. press next + play for next song.
Show Sensor data
Whit this code you can show Sensor data on a screen surface.

replace itemname "[item]" for "[Test]"

For this example you need:
  • a sensor block whit "[test]" and "Sensor" in it name.
  • a screen, programable block, or cockpit whit "[test]" and "[lcd][1]" in it name
  • a contol seat, Cockpit whit "[test]" and "[Controle]" in it name or a Remote whit "[test]" and"[remote]" in it name + antenna.

// sleep,0 remove all,[Item] add all,[Test] itemname,[Test] pittag,[Controle] remtag,[remote] lcdtag,[lcd] //mouse,Screen 0 //mouse mode,true //handbrake switch,false // Define a screen whit the tag [LCD][1] [lcd],[1],0,Screen 0,0,0,0,0 // Sensor on/off button output,Screen 0, ,2|1,20|1,ant,20,20,180, ,0.7,Sensor,term,OnOff, , input,Screen 0, ,2|1,20|1,ant,20,20,180,##<#> ,0.4,Sensor,sens , , , // Sensor result headline object,Screen 0, ,2|1,10|2,SquareFilled,10|1,2|1.9,0,sensor results,0.5,255,255,255, // Sensor readout input,Screen 0, ,20|5,10|5.5, ,10|6 ,10|4, 0, Name ,0.5,Sensor, sens <list> <name> , , , input,Screen 0, ,20|12.5,10|5.5, ,10|6,10|3.5,0, Rel ,0.5,Sensor, sens <list> <rel> , , , input,Screen 0, ,20|17.5,10|5.5, ,10|6,10|1.5,0, Time ,0.5,Sensor, sens <list> <time> , , ,

if you put the cursor on the antenna symbool en press Q, it will show the sensor data.

in this case:
  • object name
  • object relationship to founder of your faction
  • time of detection in hh:mm
Multiple Pages on 1 screen
Whit this code you can show or hide other objects on a screen(s), This way you can make Pages on screen(s).

This code work whit the memory option of the Script, first we make a button (output) thats write a "Value" to the memory. You can see de memory, if you write "log" in de name of the program block. scrol down in the right-bottum of the K menu you can see a log of the script.
In the Chapter -----MEMORY----- you can see what is in the memory.

output,Screen 0, ,6|1,20|1,SquareFilled,10|1,3|1,0, page 1,0.5, ,mem ,S1|P1, ,

screenname
Screen 0 ( if we are on screen 0)
Memory
space, We only what to write something to the memory, so we leave this part blank.
X
6|1 (this will divide 2 and place 1= center of surface)
Y
10|9 (this will divide 10 and place 9= bottum of surface)
Shape
SquareSimple (so we can see the link as a Square on surface)
H
10|1 (this will divide 10 x1 = 1/10 height )
W
3|1 (this will divide 10 x1 = 1/1 width)
0
rotation of object in degrees
text
Page 1
0.5
text size
space
no block name to adress
mem ,
we want to write someting to the memory
S1|P1,
name op memory item "S1", | "P1" value, (or status)
,
no further arguments, needs to be there.

Now we have to make some objects that we want to show in page 1;
il make 2 text collum on page 1. in this case we use object.

object,screenname,memory,X,Y,Shape,H,W,°, text, Şize, R, G, B, status, ,

note: in memory part we set "S1 P1", these opjects only shows wen "S1 P1" is in de memory.

object,Screen 0,S1 P1,4|1,20|11,SquareFilled,10|9,4|2,0,first collum page 1,0.5,255,255,255, , , object,Screen 0,S1 P1,4|3,20|11,SquareFilled,10|9,4|2,0,second collum page 1,0.5,255,255,255, , ,

We make another 2 button and two pages. Page 2 has 2 alineas, Page 3, 2 collums and an alinea underneed.
output,Screen 0, ,6|1,20|1,SquareFilled,10|1,3|1,0, page 1,0.5, ,mem ,S1|P1, , object,Screen 0,S1 P1,4|1,20|11,SquareFilled,10|9,4|2,0, first collum age 1 ,0.5,255,255,255, , , object,Screen 0,S1 P1,4|3,20|11,SquareFilled,10|9,4|2,0, second collum age 1,0.5,255,255,255, , , output,Screen 0, ,6|3,20|1,SquareFilled,10|1,3|1,0, page 2,0.5, ,mem ,S1|P2, ,
object,Screen 0,S1 P2,4|2,20|6,SquareFilled,10|4,4|4,0, first alinea age 2 , 0.5,255,255,255, , ,
object,Screen 0,S1 P2,4|2,20|15,SquareFilled,10|5,4|4,0, second alinea age 2, 0.5,255,255,255, , ,

output,Screen 0, ,6|5,20|1,SquareFilled,10|1,3|1,0, page 1,0.5, ,mem ,S1|P3, ,
object,Screen 0,S1 P3,4|1,20|9,SquareFilled,10|7,4|2,0,First collum Page 3,0.5,255,255,255, , ,
object,Screen 0,S1 P3,4|3,20|9,SquareFilled,10|7,4|2,0,Second collum Page 3,0.5,255,255,255, , ,
object,Screen 0,S1 P3,4|2,20|18,SquareFilled,10|2,4|4,0,Second alinea Page 3,0.5,255,255,255, , ,

If you put you Cunsor on the button Page 1 and Press Q.
You can see two collums appear. In the memory you can find "S1 P1".

If you put you Cunsor on the button Page 2 and Press Q
You can see two alinea appear, the two collum disappear. In the memory you can find "S1 P2"

If you put you Cunsor on the button Page 3 and Press Q.
You can see two collums and a alinea appear,the two alinea disappear. In the memory you can find "S1 P3".

This is also possible whit "ïnputs" and "outputs" on the screen and in cobination whit the logic gates. In this example we just use 1 screen but it is posible on multiple screen at ones
Timer intern
Before we use a timer we need someting to activate it, in this example we just use a button
the button makes a memory item called "Time1" whit the Value "On". if you press Q again it just delete the Value "On" . The timer stop running, basically pausing it.

Whit "E" you give the timer "T1" a certain value, it removes the memory's "Time1" and "T1" basically resetting/stopping it

//Timer T1 count up

//Button "Q" start/pause Time 1 an "E" resets T1 output,Screen 0, ,4|3,20|1,SquareFilled,10|1,2|1,0,Timer 1 On/Off,0.7, ,mem ,Time1|On,mem,T1|30 //This shows the timer value input,Screen 0, ,4|3,20|1,SquareFilled,10|1,2|1,0, <#>,0.7, ,mem |T1, , // this line add 1 as long "Time1'' has it value "On" output,Screen 0,Time1 On ,4|3,20|3,SquareFilled,10|1,2|1,0,S0 T1,0.7, ,mem <auto>,T1|+1, , //these two lines Removes "Time1" and "T1" from the memory when the Value off "T1" hit 30 output,Screen 0,T1 30 ,4|3,20|3,SquareFilled,10|1,2|1,0,S0 T1,0.7, ,mem- <auto>,Time1 On, , output,Screen 0,T1 30 ,4|3,20|3,SquareFilled,10|1,2|1,0,S0 T1,0.7, ,mem- <auto>,T1 30 , , ,

//Timer T1 count down

We need to add a line to make sure "T1" start at "30"
change the "-" to "+" in the fourth line
and change the value "30" to "0"

note: everything that has been changed is underlined.
// Sets Value T1 to 30 when T1 dont exist
output,Screen 0, NOR|T1,4|3,20|1, ,10|1,2|1,0, ,0.7, ,mem ,T1 30, ,
//Button "Q" start/pause "Time 1" and "E" reset "T1" output,Screen 0, ,4|3,20|1,SquareFilled,10|1,2|1,0,Timer 1 On/Off,0.7, ,mem ,Time1|On,mem,T1|0 //This shows the timer value input,Screen 0, ,4|3,20|1,SquareFilled,10|1,2|1,0, <#>,0.7, ,mem |T1, , // this line removes 1 as long "Time1'' has it value "On" output,Screen 0,Time1 On ,4|3,20|3,SquareFilled,10|1,2|1,0,S0 T1,0.7, ,mem <auto>,T1|-1, , //these two lines Removes "Time1" and "T1" from the memory when the Value off "T1" hit "0" output,Screen 0,T1 0 ,4|3,20|3,SquareFilled,10|1,2|1,0,S0 T1,0.7, ,mem- <auto>,Time1 On, , output,Screen 0,T1 0 ,4|3,20|3,SquareFilled,10|1,2|1,0,S0 T1,0.7, ,mem- <auto>,T1 0 , , ,

At this time the timer doesn't controle anything, it just runs. You can see that wen timer reads a certain Value its removes the timer. This way you can use the timer to hide/ show objects an centain time, active object/block after a certain time, and so on.