Space Engineers

Space Engineers

EasyCommands
Merlin of Mines  [developer] 9 Jan, 2022 @ 7:54am
Scripting Questions
Trying to do something and not sure if/how it can work? Got troubles with your script? Let's talk! Happy to help if I can.
< >
Showing 1-15 of 201 comments
Rümmler 9 Jan, 2022 @ 10:32am 
Here we go. I want to set up a solar satellite. Basically it is a flying battery with gyros which will fly to a GPS coordinate and fly back to dock and discharge and repeat.

With some step by step debugging I managed to get like halfway done, but I am stuck for now. The script so far; numbers just to have it easier to analyse

#thats important because the script ends with "setting to discharge"
1.tell the "Solar Satellite Batteries" to supply

#we are still locked, so before we go, we unlock
2. unlock the "Solar Satellite Connector"

#without waiting the script seems to run too fast and after the unlocking process the sat just chilled around the connector, but that might have been due to Isy's solar alignment taking over. I turned that off for now to get the rough base going.
3. wait 5 seconds

#Sat is going to the preset position. Took me some time to get it running, I think it was because I didn't "wait"
4. run "Solar Satellite Remote Control"

#Satellite is waiting for recharge. When the satellite is full, it will initiate the docking sequence.
5. wait until the "Solar Satellite Batteries" ratio > 0.99

#sets the batteries to discharge. I could initiate that after docking, but it doesn't matter that much. The script reaches this step because I can observe the batteries switching from "auto" to "discharge" at around 99,4 % or so.
6. set the "Solar Satellite Batteries" "ChargeMode" property to 2

#For some reason, this does not work. As for now isy's solar alignment is not running for debugging purposes, so there is no collision with that. Also, when manually doing what I wrote in the script, it works fine. I run "solardocking" and the sat flys back to the designated connector and docks, batteries discharging. It is Isy's Easy Docking script from the workshop.
7.tell "Solar Satellite Docking Script" to run "Solardocking"

#couldn't test that yet since I am stuck in step number 7, but the syntax is identical to 5. and I guess it will work. Another problem, unrelated to the script: SE does not prioritize discharging these batteries, I guess they are low in the hierachy. The grid is not really using that power, despite having capacities to drain it.
8.wait until the "Solar Satellite Batteries" ratio < 0.05

#should start at 1. again, switching the battery mode to auto and fly for the next round
9.repeat
Last edited by Rümmler; 9 Jan, 2022 @ 10:36am
Merlin of Mines  [developer] 9 Jan, 2022 @ 1:32pm 
Cool Program! I think I see the issue.

7.tell "Solar Satellite Docking Script" to run "Solardocking"

"Script" isn't a valid block keyword for a "Programmable Block". you'll want to add "program" after your "Solar Satellite Docking Script" to indicate that it's a program. Right now it's looking for the first keyword in your selector that is a block type, which is "Solar", so it's looking for solar panels.

tell the "Solar Satellite Docking Script" program to run "Solardocking"
Rümmler 10 Jan, 2022 @ 9:38am 
Works like a charm! Still have the issue that the batteries are not properly discharging but that seems to be a vanilla SE issue.

How is the script reading line 7? My guess is "run" is a trigger to fire up either a remote control or a programmable block. Does the script check for block names or is it more flexible in that regard? I thought that "Solar Satellite Docking Script" with the quotation marks let the script check if it can find a block with that exact name.

I already have another idea in mind for the next program: I have a minerdrone which is currently running to GPS coordinates when I tell it to (by logging in via K - menu), then I wait and check manually when it is there, mine a bit and then a combo of remote control and docking script will bring the drone back, saving me time. I know that there are some automated mining scripts, but I think it's fun enough to automate my system a bit. I want a sound to be played when the drone reaches the mining area, so I have my first cross grid project - while having to figure out how to tell the program to hit the next step when reaching a GPS coordinate.

If you want to use that solar satellite as an example, I wouldn't mind if you post it on your page. Maybe some other newbies can benefit from it.
Merlin of Mines  [developer] 10 Jan, 2022 @ 4:27pm 
It's actually simpler than that. EasyCommands has the idea of "Selectors", which represent a block or group of blocks. Selectors also includes a block type, which represents what kind of block you are interacting with.

By default, any string in double quotes is considered as a possible selector. EasyCommands parses each string and looks whether that string contains known block type keywords. If one exists, it considers the string as a possible selector, meaning it might reference a set of blocks with the given name with the given block type.

Optionally, you can declare the block type to EasyCommands so that it knows that (1) it is definitely a selector, not just a string, and (2) you are trying to get a specific block type.

This is useful if you want to create a Group of blocks which contains multiple block types and then want to grab specific block types from the selector.

Example:
#turn on all lights from the "Garage" block group
turn on the "Garage" lights


You can take a look through the website to get a better idea of how selectors are created and used.

https://spaceengineers.merlinofmines.com/EasyCommands/selectors
Merlin of Mines  [developer] 10 Jan, 2022 @ 4:30pm 
Take a look at the Follow Me Ship example for a good example of cross grid communication, sending location information across grids, and executing a command once the destination is reached:

https://spaceengineers.merlinofmines.com/EasyCommands/examples/shipFollow
Rümmler 15 Jan, 2022 @ 8:33am 
I checked out that follow script, but overall the garage door example was easier to understand for me.

Got some rework done for the solar satellite, since it got lost in space. I think the issue was that the script starts at line 1 after reloading a save game, which will make the grid to do something it shouldn't. I honestly cannot reconstruct why it happened, but my sat just flew out of antenna range and never came back. :D


Sooo, Sat 2.0 here we go. It is mainly an oxygen farm now since energy is not really an issue anymore, me being too lazy to grab ice on the other hand is a big issue.

I don't understand to 100% what I have done. I assume starting a line with ":" makes it into a block of lines, so instead of going from A to Z the script has different blocks you can adress by "goto" and when you want the script to end, you tell it to go to a block which is just an infinite loop of waiting. Am I correct here?


#Script which is run on the satellite:

#I assume the script starts here and then knows "Ahh, ok, my name is SunfarmSat and I will be adressed by that in the future"

:setup
listen "SunfarmSat"
goto "listen"

#"Now that I know my name, I will just wait until told otherwise"

:listen
wait 1
replay

#Button 1 for starting the Satellite from my base.

#Whenever the listener (the satellite) is being told "SunfarmStartSequence", it toggles the connector, waits, flies to the preset GPS and goes back to the waiting loop. That would mean I can get a button in my base, press it and the satellite starts the farming process; waiting at the GPS spot. Am I right?

:SunfarmStartSequence
toggle the "Sunfarm Connector"
wait 3 seconds
enable "Sunfarm Remote Control" autopilot
goto "listen"

#Button 2 for bringing the satellite back to base.

#With this I want to tell the satellite to run the Docking script and return back to base, then go back to the waiting loop. So after it finished the docking, the first button should make it go back to the collection area.

:SunfarmDockingSequence
tell the "Sunfarm Docking Script" program to run "Sunfarm Docking"
goto "listen"


________________________________

#Script which is run on the base:

#I want to assign this to a button. The button is on the base itself and will initiate the launchprocess I set up on the satellite

:SunfarmStart
send "goto SunfarmStartSequence" to "SunfarmSat"

#This is the button 2 to trigger the docking sequence, bringing the sat back to base.

:SunfarmDocking
send "goto SunfarmDockingSequence" to "SunfarmSat"







This scripting is a bit more elaborate, but I enjoy the possibilites it should give me. Instead of just running a loop, I can adress certain maneuvers manually, giving me more control. I haven't tested it yet - do you think I am on a right path here?
Last edited by Rümmler; 15 Jan, 2022 @ 8:35am
Merlin of Mines  [developer] 15 Jan, 2022 @ 8:47pm 
Hey @Rümmler.363VD ✠! Sorry you lost your satellite!

You're definitely on the right track. What you have should work reasonably. Make sure your satellite is still in range of your base, and within rendering distance, though.

:functionName is how you define functions in EasyCommands, which help break up your code into smaller re-usable pieces. Check out the page on functions for more info:
https://spaceengineers.merlinofmines.com/EasyCommands/functions


I don't think you actually need the "goto listen" in SunfarmStartSequence, as the "listen" thread is still running. Check out the threads page for more info.
https://spaceengineers.merlinofmines.com/EasyCommands/threads


:setup
listen "SunfarmSat"
goto "listen"

:listen
wait 1
replay

:SunfarmStartSequence
toggle the "Sunfarm Connector"
wait 3 seconds
enable "Sunfarm Remote Control" autopilot


:SunfarmDockingSequence
tell the "Sunfarm Docking Script" program to run "Sunfarm Docking"
goto "listen"



I'm pretty sure you don't need the "goto listen" in SunfarmStartSequence or SunfarmDockingSequence. By invoking via another script you're starting a new "thread" to execute that task, so the "listen" thread is still just listening. In fact, over time i think you'll accumulate "listening" threads and break the program (max is 50 active threads).

https://spaceengineers.merlinofmines.com/EasyCommands/threads

Just curious, do you have 2 EasyCommands scripts, or are you running another programmable block that's running a different script?

tell the "Sunfarm Docking Script" program to run "Sunfarm Docking"


If it's EasyCommands on both, you can likely condense to just 1 EasyCommands program using functions.

Good luck! If you've got a video or gif i'd love to see it.
Rümmler 17 Jan, 2022 @ 2:50pm 
Thanks to your help and some trying here and there, it is finally working and I am proud of that little achievement. Was a lot of fun cooking that up!

So, here is the working setup. Free to use for all. I am running Industrial Overhaul and some other mods, but the Satellite is made out of vanilla blocks and running another script, so it should on other worlds, too.

The base runs a Programmable Block named "Base - Sunfarmer PC"
The satellite is running a Programmable Block named "Sunfarmer - Easy Command"


The base runs this script:

:main
wait

:SunfarmStart
send "goto SunfarmStartSequence" to "SunfarmSat"

:SunfarmDocking
send "goto SunfarmDockingSequence" to "SunfarmSat"



The satellite runs this script:

:setup
listen "SunfarmSat"
goto "listen"

:listen
wait 1
replay

:SunfarmStartSequence
disconnect the "Sunfarmer - Connector"
wait 3 seconds
turn on "Sunfarmer - Remote Control" autopilot

:SunfarmDockingSequence
tell "Sunfarmer - Docking Program" program to run "Sunfarm Docking"





The Docking Script is another workshop script, done by the talented Spug and is called "Spug`s Auto Docking 2.0". I set up a connector on my base and what the script does is flying the satellite there and connect.

Next steps: I want to have a LCD in my base printing the stats of the satellites O² tank and and an automatic return on filling a certain level of O². Gotta check out how to print stuff on LCD; I already saw something on your website.

I think the latter should be in the ":listen" thread?
Something like "if the tank is > 0.99 goto :SunfarmDockingSequence." My guess is that the :listen thread is the right place for that because it's always running, unless the script is being told to do one of the other threads.

As for the video: I will record something soon, but I will be rather busy this week. I try to go for it on the next week!
Last edited by Rümmler; 17 Jan, 2022 @ 2:52pm
Merlin of Mines  [developer] 17 Jan, 2022 @ 7:25pm 
Awesome! Thanks for sharing.

I suggest creating an async thread to send the updates. The update can happen in parallel and independently of which function is running.
EDDO84 18 Jan, 2022 @ 4:51pm 
Heey, prob 3 stupid questions, but here it goes,

1)

I don't know if it is me, but for some reason i cannot get your example crane like drill arm to work as intended. Like you wrote it. On my pc the middle piston would not work as intended?,

:main
set drillCockpit to "[DB] Drill Cockpit"
set rotationSensitivity to 0.25
async controlDrill

:controlDrill
set the "[DB] Drill Rotor" velocity to (rotationSensitivity * $drillCockpit right roll)
set the "[DB] Drill Middle Hinge" velocity to (rotationSensitivity * $drillCockpit downwards roll)
set the "[DB] Drill Bottom Piston" velocity to the $drillCockpit forwards input
set the "[DB] Drill Middle Pistons" velocity to the $drillCockpit clockwise roll
set the "[DB] Drill Front Hinge" velocity to the $drillCockpit upwards input
set the "[DB] Drill Front Piston" velocity to the $drillCockpit right input
replay

I was able to swapp the "[DB] Drill Rotor" with the "[DB] Drill Middle piston" So i rotate the crane with q and e and i can use the middle pistons now all functions works as intended. Do you know why i need to swapp them and why they do not work as your example?


2)

Would it be possible to add a extra combination key? like Shift + forwards?
So i can have more options and how would you be able to do that. i tried it with a combination of commands like:

if the input key = shift + forwards
set the "[DB] Drill Bottom Piston 2" velocity to the $drillCockpit forwards input

or
set the "[DB] Drill Bottom Piston 2" velocity to the $drillCockpit forwards + shift (or control or name your key) input

Offcourse i can always group the pistons (like you did in your example) but i wanted to create extra options so i can use them separate from each other.


3)

Why the use of "[DB] Drill Rotor" I can't find no other use of it other than naming my parts? Cause with out [DB] it works fine to?? i thought you placed it in for a reason? but i can not find it?
Merlin of Mines  [developer] 18 Jan, 2022 @ 7:23pm 
@EDDO84

1. My guess is that "[DB] Middle Pistons" which is expected to be a block group, not an individual block, was the issue for you.

2. Unfortunately I don't have arbitrary keyboard input available; only the input values are provided based on the user set controls for movement and rotation.

3. [DB] was just the naming convention for "all the things related to Drillbert". As long as the name of the part includes what kind of part it is, you can resolve the part by name using just it's name (or group name). So anything with " Rotor " in the name is presumed to be a rotor unless you specify a block type specifically, like "My Rotor" piston

Check out Selectors for more information:
https://spaceengineers.merlinofmines.com/EasyCommands/selectors
Saros 19 Jan, 2022 @ 1:24am 
Apologies if I'm missing something obvious but I'm trying to get the script to check every second or two if any of my landing gear are locked to something and if any of them are trigger a timer block which does a few actions. Unfortunately the trigger (3rd) line can't be parsed. Ideally I'd have a specific timer triggered instead of all as well.

:main
if magnet locked
trigger timer
exit
wait
replay
EDDO84 19 Jan, 2022 @ 6:42am 
@Merlin of Mines

as far as the pistons were concerned, I realized that it was a group. The only thing I could think of myself was that it may have had to do with weight. and the way q and e approach excelleration. I think that in the form of q and e there is no multiplication because when I turn my rotor now it always turns at the same speed where I could make it spin faster or slower under the mouse. does this sound logical or????
Cause i used modded longer pistons, i tried this morning the vanilla ones and they do work normal with the original script example. so weight was the only logic thing i could go on.

As for 3) it is as i suspected, i think i was just confused by the [ ]. But thanx for the reply and confirming so i dont longer surge to make sense of things the wrong way.



Originally posted by Merlin of Mines:
@EDDO84

1. My guess is that "[DB] Middle Pistons" which is expected to be a block group, not an individual block, was the issue for you.

2. Unfortunately I don't have arbitrary keyboard input available; only the input values are provided based on the user set controls for movement and rotation.

3. [DB] was just the naming convention for "all the things related to Drillbert". As long as the name of the part includes what kind of part it is, you can resolve the part by name using just it's name (or group name). So anything with " Rotor " in the name is presumed to be a rotor unless you specify a block type specifically, like "My Rotor" piston

Check out Selectors for more information:
https://spaceengineers.merlinofmines.com/EasyCommands/selectors
Last edited by EDDO84; 19 Jan, 2022 @ 7:06am
EDDO84 19 Jan, 2022 @ 7:00am 
@Saros

Originally posted by Saros:
Apologies if I'm missing something obvious but I'm trying to get the script to check every second or two if any of my landing gear are locked to something and if any of them are trigger a timer block which does a few actions. Unfortunately the trigger (3rd) line can't be parsed. Ideally I'd have a specific timer triggered instead of all as well.

:main
if magnet locked
trigger timer
exit
wait
replay

I think I know the answer to this..
Instead of triggerring all timers called timer
try to name your specific timer in the control panel. and name it: timer LandingGear.
you can use
trigger "timer LandingGear"
This way, you indicate that you only want to activate that specific timer with the name timer LandingGear.
Hope this will help you out!
Merlin of Mines  [developer] 19 Jan, 2022 @ 7:30am 
@Saros

Not quite sure what was going on with yours, but this script works locally for me:
https://pastebin.com/BLUREmtF


Here's a simpler version too, using the "when" condition, and only triggering the timer you intended.
https://pastebin.com/CeffY5gV


Check out Selectors and Conditions for more info:
https://spaceengineers.merlinofmines.com/EasyCommands/selectors
https://spaceengineers.merlinofmines.com/EasyCommands/commands#conditional-commands
< >
Showing 1-15 of 201 comments
Per page: 1530 50