Space Engineers

Space Engineers

View Stats:
IvanGogh May 16, 2022 @ 3:14pm
Question about coding AI ships in the game.
For someone that is fairly used to C# and can make a very basic game like say, Pong on Unity, how hard would it be to program a simple but functional AI for a mining drone, for example?

I am aware you can download scripts and that you don't have to code stuff yourself, but I really wanted to give it a shot.
< >
Showing 1-3 of 3 comments
ShadedMJ May 16, 2022 @ 3:59pm 
I write scripts. My post history has a bunch of them I've written for other players. I think I'm the player writing the most scripts.

From the workshop, I suggest this one for a mining script:
https://steamcommunity.com/sharedfiles/filedetails/?id=1507646929

Bear in mind that the Space Engineers C# environment is ... primitive compared to a standard programming environment. The script must complete fairly quickly or a "script too complex" message will show up. I suggest not using while loops at all. Thread.Sleep() is not allowed. Almost all scripts end up to be state machines. The programmable block is not good at displaying error messages, so making your own error messages is better than a crash log. Space Engineers uses an older version of C# (version 6 I think), so no tuples allowed.

I suggest you get Microsoft Visual Studio for a C# compiler. There are tutorials on connecting the compiler to the Space Engineers C# library. Makes programming much easier. Google "space engineers C#" to get piles of tutorials. I and others here can help out.

Now for the mining drone:

Essentially its using drills, monitoring ship status (especially cargo container %full), moving, docking to a station, unloading ore, undocking, moving back, rinse and repeat.
I think the hardest part is going to be moving around. This can be done with a remote control block, but sometimes stuff goes wonky.
IvanGogh May 17, 2022 @ 9:55am 
Originally posted by ShadedMJ:
I write scripts. My post history has a bunch of them I've written for other players. I think I'm the player writing the most scripts.

From the workshop, I suggest this one for a mining script:
https://steamcommunity.com/sharedfiles/filedetails/?id=1507646929

Bear in mind that the Space Engineers C# environment is ... primitive compared to a standard programming environment. The script must complete fairly quickly or a "script too complex" message will show up. I suggest not using while loops at all. Thread.Sleep() is not allowed. Almost all scripts end up to be state machines. The programmable block is not good at displaying error messages, so making your own error messages is better than a crash log. Space Engineers uses an older version of C# (version 6 I think), so no tuples allowed.

I suggest you get Microsoft Visual Studio for a C# compiler. There are tutorials on connecting the compiler to the Space Engineers C# library. Makes programming much easier. Google "space engineers C#" to get piles of tutorials. I and others here can help out.

Now for the mining drone:

Essentially its using drills, monitoring ship status (especially cargo container %full), moving, docking to a station, unloading ore, undocking, moving back, rinse and repeat.
I think the hardest part is going to be moving around. This can be done with a remote control block, but sometimes stuff goes wonky.
Can you possibly have a drone use multiple simpler scripts in order to finish a task?
ShadedMJ May 17, 2022 @ 1:04pm 
Originally posted by IvanGogh:
... Can you possibly have a drone use multiple simpler scripts in order to finish a task?
Sure. Trying to pass results from one script to another can be done, though it takes some effort.
IMyProgrammableBlock PB2=GridTerminalSystem.GetBlockWithName("Progrqammable Block 2") as IMyProgrammableBlock; PB2.TryRun("argument");

Some stuff I thought about afterward. Ore detector blocks are intended to provide information to the player and you can't use a script to get information out of it. Same with antennas. If scripts could get info from them, then the game would be called Automation Engineers for script writers only.

Some advanced stuff are getting programmable blocks on different grids to talk to each other, and camera raycasting.
< >
Showing 1-3 of 3 comments
Per page: 1530 50

Date Posted: May 16, 2022 @ 3:14pm
Posts: 3