Space Engineers

Space Engineers

EasyAPI
597 Comments
Delta99 20 Jun, 2021 @ 8:14pm 
I think the author is long gone
jbo96 20 Jun, 2021 @ 7:21pm 
any updates to this?
Delta99 23 Feb, 2020 @ 6:53pm 
Post it up on pastebin or something maybe
tismoj 15 Feb, 2020 @ 11:16am 
Hi, I may have fixed the errors but I haven't any existing scripts that use this yet since I only came across this today and I just wanted to use it so I tried to fix it. could someone please verify this for me?

It should get rid of the errors but a lot of deprecation warnings still remain I just wanted to try this API first, and hopefully, someone else could verify that it still works on their existing code

Just replace the very long last line, the one with the minified library code with this:
<I tried to paste the very long line here but it exceeded the 1000 char limit>

Any suggestion as to how I could send the fix for everyone here?
gaimi.darai 17 Apr, 2019 @ 2:57pm 
This is now returning Check Code error:

42/19765, There is no argument that corresponds to the required formal parameter 'items' of MyInventory.GetItems
LukeStrike 7 Nov, 2018 @ 5:29am 
Works pretty fine again, thanks Rock ;)

In my example https://gtm.steamproxy.vip/workshop/filedetails/discussion/379297410/357288572132613477/ everything goes well :)

LKS
Delta99 6 Nov, 2018 @ 9:40pm 
Nice to see you back in action rockyjvec. I had to fix this myself a few months back.
rockyjvec  [author] 6 Nov, 2018 @ 6:19pm 
Fixed the compile error.
Delta99 21 Jul, 2018 @ 12:57pm 
Looks like this is broke now. Any plans for updating?
zmiller1 30 Jul, 2017 @ 8:52am 
Does this still work?
Montmorency 6 Dec, 2016 @ 3:30pm 
Hello, is it compatible with medieval engineers?
Mazen IIXIS 25 Nov, 2016 @ 1:22pm 
Are the abstract class still using the long Milliseconds, long Seconds, long Minutes, long Hours, etc?
rockyjvec  [author] 4 Nov, 2016 @ 10:47pm 
I fixed the warnings.
Delta99 1 Nov, 2016 @ 7:34pm 
@Comet, that would be great
Comet 31 Oct, 2016 @ 9:21pm 
@rockyjvec Thanks for the merge, @Delta99 I might take a look at some of the warnings in the next few weeks and submit some fixes for them if I have time.
Delta99 31 Oct, 2016 @ 7:27pm 
@rockyjvec, same here plus into other games at the moment. I updated my script with your updates now. Got a bunch of warnings but no worries, still works fine.
rockyjvec  [author] 31 Oct, 2016 @ 7:02pm 
@Delta99, yeah, I've been really busy and haven't had much time for Space Engineers the last few months. :-(
Delta99 31 Oct, 2016 @ 6:59pm 
@rockyjvec, good to see you are still around
rockyjvec  [author] 31 Oct, 2016 @ 6:58pm 
Thanks, I just merged your pull request and published the new version to steam workshop.
Delta99 30 Oct, 2016 @ 4:22pm 
@Comet, great, I think I'll grab your version soon and fix my mod
Comet 30 Oct, 2016 @ 4:21pm 
@Delta99 It seems so. @rockyjvec, I've submitted a PR to your project on Github with the fix to get it compiling in game again: https://github.com/rockyjvec/EasyAPI/pull/13
Delta99 23 Aug, 2016 @ 4:32pm 
Is this busted since the most recent stable update on Aug 18?
LukeStrike 21 Jul, 2016 @ 7:12am 
@rockyjvec:Hello. Still working on EasyAPI ?

LKS
LukeStrike 24 Jun, 2016 @ 10:00pm 
@rockyjvec: As you can see I've added some "Learn by examples" topics in the discussions. I think this is not a bad place to do that (despite the code format) and that it will be useful for people using EasyAPI.

LKS
LukeStrike 22 Jun, 2016 @ 12:25am 
@rockyjvev: there is a problem with the GetBlock() method.

If you write this:

Blocks.Named("LCD [AP] (O1)").GetBlock(0).<whatever you want>

If no block was found you cought an exception like "index out of range". A better way should be "do no action" don't you think ?

LKS
LukeStrike 22 Jun, 2016 @ 12:00am 
(... cont)
And you can use it like that:

public class Example : EasyAPI
{
public Example(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action<string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime)
{
// Start your code here
Blocks.NamedLike("Blabla").GetBlock(0).BlaBla();
}
}

And f.e. a block named "PB (Blabla)" will echoes "PB (Blabla) BlaBla" ... a silly example but yes, a proof of concept ;)

LKS
LukeStrike 21 Jun, 2016 @ 11:53pm 
(... cont)
You can use Echo in extensions like this one:


} //Trick: close the Program class so we can define Extensions classes
public static class EasyEXTBlaBla
{
public static void BlaBla(this Program.EasyBlock easyblock)
{
Program.Echo(easyblock.Name() + " BlaBla");
}
//Trick: no closing brace here, SE will close it automaticaly

(cont ...)
LukeStrike 21 Jun, 2016 @ 11:51pm 
@rockyjvec: again about the Echo ... if you replace your code by this one:

/*********************************************/
/*** Advanced users only beyond this point ***/
/*********************************************/

Example state;
public static Action<string> Echo;

void Main(string argument)
{
Program.Echo = (this as MyGridProgram).Echo;

if(state == null)
{
state = new Example(GridTerminalSystem, Me, Echo, ElapsedTime);
}

// Set the minimum time between ticks here to prevent lag.
// To utilise onSingleTap and onDoubleTap, set the minimum time to the same
// time period of the timer running this script (e.g. 1 * EasyAPI.Seconds).
state.Tick(100 * EasyAPI.Milliseconds, argument);
}

(cont ...)
LukeStrike 21 Jun, 2016 @ 10:54pm 
Ok, my first EasyAPI extension (EasyEXT...)

In this case EasyEXTHelpersColors here: http://pastebin.com/TZg7HSLd

It does a conversion from a string to a color, like this:

public void Main(string argument)
{
Color color = "{R:10 G:20 B:30 A:255}".ToColor();
Echo(Convert.ToString(color));
}

@rockyjvec: u to you to say to me where store my code ? I have 3 choices: pastebin, githup (if I have an access to your repository let's say in a subfolder like "EasyEXT", of even in the discussions section here ?

LKS
LukeStrike 21 Jun, 2016 @ 9:57am 
@rockyjvec: Feedback: about your Echo solution: works perfectly.

I think it should be cool to implement it in the EasyAPI core ? So EasyAPI extensions can use it (useful for debuging)

LKS

LukeStrike 19 Jun, 2016 @ 4:35pm 
Last one ... Extend EasyAPI is cool. Yes it forces the user to add extra code after the minified core code (in fact: just some copy/paste) Hot such a pain and will allow to publish "modules" (Extensions, in fact) that the user may want to include, or not. So I think that some of the core code should be more light (no real nead for LCDs to be included in, f.e ?) and that everyone can customize its own scripts. And maybe we can provide some "all-in-one" packages (minified), for some specific usages (just for displaying ship's infos the same way CAL does, f.e.)

I do like MMaster and CAL (one of the most powerful ones) but I don't want to depend any more on it for some "extra" features, like triggering an event in case of critical value (refused) or display only the informations I need (f.e. one line saying that your ions are 7/10 On, instead of having a huge list of 10 ions displaying On/Off)

LKS
BTW: possible to have some tchat on Steam sometimes ? Much more faster, I think ;)
LukeStrike 19 Jun, 2016 @ 4:02pm 
@rockyjvec: I'm working on ESY Extensions for properties. One of them returns a PropertyID TypeName as a String (ok). The idea is to use it to get a Property value (as a string) or set it's value (idem) without having to be concerned by it's type (you don't have to write a method for each possible type)

Get works for Boolean, String ... issues with certain types such as StringBuilder (Keen's known bug, again) and other exotic ones (no way to handle them at this time).

When (partially) done I will publish it (on pastebin ?) and give you the link. I will use it for myself (to display only certain properties values on LCDs) but up to you to integrate it in the core code (usefull to re-write the DebugDumpProperties, f.e.)

More to come ;)
LKS
PS: when/if I have time I will try to work on autopiloting, etc ... Again a shame that Keen does not give any access to the remote control (tautopilot to a GPS point) neither to jump drives (idem). So a bit much more complicated :(

LKS
LukeStrike 19 Jun, 2016 @ 3:30pm 
@rockyjvec: Thanks for your reply, I will try it ASAP;)

If I understand well: "public static Action<string> Echo;" is a kinda pointer to a function (like in C, C++) or am I wrong ?

So you link it to the KeenAPI Echo at runtime and then you can call it from outside and it will be "forwarded" ?

BTW Action is a "generic" (?) type provided by the KeenAPI ?

LKS
rockyjvec  [author] 18 Jun, 2016 @ 2:15pm 
@LukeStrike, one possible way around the Echo issue you had is to make a static version of the Echo function in the program class like this:

public static Action<string> Echo;

void Main(string argument)
{
....Program.Echo = (this as MyGridProgram).Echo;
}

then in your extension method you can call Echo like this:
Program.Echo("hello world");
LukeStrike 12 Jun, 2016 @ 7:43pm 
BTW: is there a place on steam where we can put some pieces of code as examples for people that want to use EasyAPI ? (I have some, such as auto closing doors based on events etc, that can be usefull for "EasyAPI beginners" ;). And this way you can add it in the popular discussion like "Alert status system" ?

LKS
LukeStrike 12 Jun, 2016 @ 7:33pm 
@rockyjvec: this works also but man, what a pain just for an Echo :/ So if you can give me a solution of how to use such methods out of the program class, it will be very appreciated :)


// Start your code here
String output = "Say Hello:\n";
Blocks.NamedLike("[EXT]").Hello(ref output);
Echo(output);
...(after the minified EasyAPI code)
} //Trick: close the Program class so we can define Extensions classes
public static class EasyAPIExtensions
{
public static Program.EasyBlocks Hello (this Program.EasyBlocks easyblocks, ref String output)
{
for(int i = 0; i < easyblocks.Count(); i++)
{
easyblocks.GetBlock(i).Hello(ref output);
}

return easyblocks;
}

public static Program.EasyBlock Hello (this Program.EasyBlock easyblock, ref String output)
{
output = output + "Hello " + easyblock.Name() + "\n";

return easyblock;
}
//Trick: no closing brace here, SE will close it automaticaly
LKS
LukeStrike 12 Jun, 2016 @ 1:16am 
@rockyjvec: ok fine but I resolved the problem this way:

} //Trick: close the Program class so we can define Extensions classes
public static class EasyAPIExtensions
{
public static Program.EasyBlocks Hello (this Program.EasyBlocks easyblocks)
{

for(int i = 0; i < easyblocks.Count(); i++)
{
easyblocks.GetBlock(i).Hello();
}

return easyblocks;
}

public static Program.EasyBlock Hello (this Program.EasyBlock easyblock)
{
//Program.Echo("Hello " + easyblock.Name());

return easyblock;
}
//Trick: no closing brace here, SE will close it automaticaly

But the fact Bocks is now public is a good point. New problem: as you can see (commented) I can't get any access to the Echo command :/ Any Clue ?

BTW this works also:
// Start your code here
Blocks.Named("").Hello();
Echo("OK");
But the fact is I cannot have any aoutput from the Hello command itself :/
LKS
rockyjvec  [author] 11 Jun, 2016 @ 4:55pm 
@LukeStrike, It was because Blocks is a private variable. I just changed it to public and uploaded a new version of EasyAPI. It should work with the new version.
LukeStrike 11 Jun, 2016 @ 2:33pm 
@rockjvec: ok this works:
} //Trick: close the Program class so we can define Extensions classes
public static class EasyAPIExtensions
{
public static Program.EasyBlocks Hello (this Program.EasyBlocks easyblocks)
{
return easyblocks;
}
//Trick: no closing brace here, SE will close it automaticaly

But the problem is that I have no access to the Blocks attribute ...
When I try ...
for(int i = 0; i < easyblocks.Blocks.Count; i++)
{
}
It says to me that Program.EasyBlocks contains no definition of Blocks, neither Extention method ... so how can I have access to the attribute of the extended class ?

LKS
rockyjvec  [author] 11 Jun, 2016 @ 11:43am 
@LukeStrike, since EasyBlocks and EasyBlock are actually nested inside the Program class I mentioned, you have to reference them as follows in your extension class:
Program.EasyBlocks
Program.EasyBlock
LukeStrike 11 Jun, 2016 @ 6:00am 
@rockyjvec: yes tha's what I understood and did but when I add this code at the end of the EasyAPI (right after the minified code):

} //Trick: closte the Program class so we can define Extensions classes
public static class EasyAPIExtensions
{
public static EasyBlocks Hello (this EasyBlocks easyblocks)
{
for(int i = 0; i < this.Blocks.Count; i++)
{
this.Blocks[i].Hello();
}

return this;
}
public static EasyBlock Hello (this EasyBlock easyblock)
{
echo("Hello " + easyblock.Name());

return this;
}
//Trick: no closing brace here, SE will close it automaticaly

It says to me that the type or namespace EasyBlocks can not be found. Same for EasyBlock (what a surprise !?). So how can I extend them ?

LKS
rockyjvec  [author] 11 Jun, 2016 @ 2:21am 
Basically, everything you write in the programming block gets added inside a Program class like this:

class Program {
....void Main()
....{
....}
}

extension classes cant be in another class so we insert a closed bracket to break out of the Program class like this:
....void Main()
....{
....}
} // extra close brace

class TestExtension { // unterminated brace at the end

On the backend, what actually happens is this:
class Program {
....void Main()
....{
....}
}

class TestExtension { // this was unterminated in our code but space engineers still has the next brace which used to end the Program class but now ends our TestExtension class
}

rockyjvec  [author] 11 Jun, 2016 @ 2:12am 
@LukeStrike, here is a working example of how to create extensions: http://pastebin.com/UP5WDUbY

For that example I just extended the string class to have an output method which outputs the string to the programming block via an exception.

You have to add an end bace at the end of the minified code, then put your extension class, then leave off the last end brace in your extension class.
LukeStrike 10 Jun, 2016 @ 2:13pm 
@rockyjvec: not sure to well understand ... is the invisible brace automaticaly added or have I to add it by myself at the end of your minified code ?

Can you give me an example of a working class extension please ?

LKS
rockyjvec  [author] 10 Jun, 2016 @ 8:56am 
@LukeStrike,

The terminating brace I mentioned below should appear at the very end of the script. So in the case of EasyAPI it would go after all the easyapi code. This is exactly the method I was going to use a few months ago to add features to easy api in a modular way.
rockyjvec  [author] 10 Jun, 2016 @ 8:54am 
@LukeStrike, I'll try to add that to debugdumpproperties later today.

Yes, you can add methods to easyapi using extension methods like you did below. The trick is that you have to trick the programming block in to terminating the parent class and then leave off your last end curly brace so the one in the parent class terminates it. I'll try to give you a working example later today but here is the general idea

void Main(str args)
{
}
} // this brace closes the parent class that is not visible in the programming block

// define your extension classes here
class ExtensionClass {
// leave off the closing curly brace because the parent class closes it for you

// note: this has been discussed in keen forums and the last I heard it was allowed because scripts are still required to follow complexity rules, etc.
LukeStrike 10 Jun, 2016 @ 3:57am 
Sorry but in the previous code the line in the for loop has to be read: this.Blocks\[i\].Hello();

(That's why the rest is in italic)
LKS
LukeStrike 9 Jun, 2016 @ 4:58am 
@rockyjvec: I really need your help on this point. When I try to extend your classes this way:

public static class EasyAPIExtentions
{
public static EasyBlocks Hello (this EasyBlocks easyblocks)
{
for(int i = 0; i < this.Blocks.Count; i++)
{
this.Blocks .Hello();
}

return this;
}
public static EasyBlock Hello (this EasyBlock easyblock)
{
echo("Hello");

return this;
}
}

Nothing works :/ I always get error messages when checking code (also whenI tried to use non static classes/methods). And I really need that for example to add a "Rename" method for EasyBlock(s) to change their names, add parsing to LCDs, etc etc ... Heeeelp me please ;)

LKS
LukeStrike 7 Jun, 2016 @ 4:51am 
@rockyjvec: now for more suggestions and questions:

Can you add in the DebugDumpProperties method:
1° the actual value it has ?
2° a way to filter the property you only want ?
So you can get a return like this: DebugDumpProperties(false, "Override");
And receive a string like "Single Override 100" only and not the whole stuff ?

Is it in C# an easy way to "overload" classes such as EasyBlocks ? Because if I want to add methods to them I prefer to add them externaly, instead of having to break your code (that I don't want and neither have to minify it again). So for example to add a thing like this (formal syntax):
EasyBlocks::MyMethod(args) ...
And then call:
Blocks.MyMethod(args) ...

Is it possible ?
LKS