Space Engineers

Space Engineers

View Stats:
This topic has been locked
Jon.Topps Jan 22, 2017 @ 3:05pm
Piston help
New to pistons, but is there actually no way to have it go forward a set amount?
What I want, is to push a button, and two pistons go forward one meter. Push it again, they go another meter. Push the second button and both go back one meter, push it again, and they go back another meter.
Is this not possible?
< >
Showing 1-14 of 14 comments
Torriador Jan 22, 2017 @ 3:23pm 
You could either set up a timer block to extend/ retract for a set amount of seconds ( depending on the speed of piston travel), or write / search for a programmable script that would would automate what you are looking for.

You could also set up a sensor array to detect a block positined at the piston head, but that consumes a lot of space. ( i made my first multi-floor elevator that way)
Jon.Topps Jan 22, 2017 @ 4:40pm 
Ahhh so it would take actual programming. I'm not too great at that, lol.

I've figured out a workaround for this, but now my pistons are doing weird things.
Every now and then the pistons will just SPAZZ right out. They just shake all over like nuts. This is definitely going to cause problems when I include this set up in my ship yard. Right now I have all four pistons velocity at 0, and they're even off. Do I need to do something else to stop them from randomly spazzing out?
dszombiex Jan 22, 2017 @ 4:52pm 
void Main(string argument)
{
var args = CheckArgument(argument);

var offset = Convert.ToSingle(args[0]);
var pistonName = args[1].Trim();

var piston = GridTerminalSystem.GetBlockWithName(pistonName) as IMyPistonBase;

if (piston == null)
{
throw new Exception(pistonName + " was either not found or is not a Piston.");
}

var currentPos = GetPistonPosition(piston.DetailedInfo);
var currentVelocity = piston.Velocity;
var newPos = currentPos + offset;

newPos = (newPos > 10.0f) ? 10.0f : newPos;
newPos = (newPos < 0.0f) ? 0.0f : newPos;

if ((offset > 0 && currentVelocity < 0) || (offset < 0 && currentVelocity > 0))
{
piston.ApplyAction("Reverse");
}

piston.SetValue("UpperLimit", newPos);
piston.SetValue("LowerLimit", newPos);

}

private String[] CheckArgument(string argument)
{
if (String.IsNullOrEmpty(argument))
{
throw new Exception("No argument provided");
}

var args = argument.Split(' ');

if (args.Length != 2)
{
throw new Exception("Incorrect number of arguments");
}

return args;
}

private Single GetPistonPosition(string pistonInfo)
{
string[] pistInfArr = (pistonInfo.Split(':'));
string[] pistonDist = (pistInfArr[1].Split('m'));
return Convert.ToSingle(pistonDist[0]);
}
dszombiex Jan 22, 2017 @ 4:54pm 
Assign button to run program with arguments, distance to be travelled, piston name.
For example, to move a piston named Bob 2 meters your argument would be:
2 Bob
or for reverse
-2 Bob
Jon.Topps Jan 22, 2017 @ 4:58pm 
Originally posted by dszombiex:
Assign button to run program with arguments, distance to be travelled, piston name.
For example, to move a piston named Bob 2 meters your argument would be:
2 Bob
or for reverse
-2 Bob
WOW thanks! I'll have to try this out!
Jon.Topps Jan 22, 2017 @ 5:20pm 
Originally posted by dszombiex:
or for reverse
-2 Bob
Oh my goodness it totally works... It's so sketchy looking, haha, like a 6x15 of welders flying across the sky, the whole thing shaking violently, hahahaha.
Thanks so much for the help!
dszombiex Jan 22, 2017 @ 5:23pm 
I can make it work on multiple pistons too if you want. Just let me know.
Torriador Jan 22, 2017 @ 5:30pm 
when configuring your piston, make sure that you ctrl + click the speed slider so that you get the piston to the "exact" speed that you need ( especially important for multiple piston lifts)
Jon.Topps Jan 22, 2017 @ 6:30pm 
Originally posted by dszombiex:
I can make it work on multiple pistons too if you want. Just let me know.
If you wouldn't mind, ya that'd be helpful.
I've tried giving it the command to the group of pistons, but it doesn't seem to accept that run command.
Jon.Topps Jan 22, 2017 @ 8:41pm 
Awesome! Thanks so much!
So for the argument, do I just say something like "6 piston1 piston2 piston3"? To move those three pistons by 6?
dszombiex Jan 22, 2017 @ 9:51pm 
Just give them all the same tag. If you have 3 pistons, name them something like [Piston] 1, [Piston] 2, etc. Then for the argument you just use 6 [Piston] and it finds anything labelled with [Piston]
Master_Nick Sep 11, 2019 @ 11:22am 
dszombiex :-) Could you paste the multi piston script here?
The Pastebin is gone.....
Dan2D3D  [developer] Sep 11, 2019 @ 11:42am 
Originally posted by Master_Nick:
dszombiex :-) Could you paste the multi piston script here?
The Pastebin is gone.....


You are in a obsolete discussion (2017) so I recommend that you create a new 2019 to ask the Froum Veterans cause the game is not the same at all now and still this year = Some Mods and Scripts have to be updated to run properly and be compatible with the "Economy game version".

Have you used the Workshop search tool to find one that is up to date?
< >
Showing 1-14 of 14 comments
Per page: 1530 50

Date Posted: Jan 22, 2017 @ 3:05pm
Posts: 14