Space Engineers

Space Engineers

LtTwinkie's Multiple Hinge Control
32 Comments
CptTwinkie  [author] Sep 23, 2022 @ 11:44am 
I'm not sure what you mean Efan. If you just want the hinge to go back and forth in a loop then you either need a different script or you will have to set something up with timers
Stefan Sep 22, 2022 @ 7:23am 
How to make script only for loop Hinge from one side to another
CptTwinkie  [author] Jul 9, 2022 @ 4:00am 
It sets the velocity in a direction and then sets a limit in that direction. The hinge will move until it hits the limit. If you want to stop the hinge then you can pass 0 or nothing as the argument to the script and it will stop
Wratox Jul 6, 2022 @ 4:36am 
Will this script never reset the velocity of the hinges to 0?
I see the check for stop conditions but 'desiredVelocity' won't become 0 since it's set to 1.0 a few lines above.
Or am I missing something?
Shinagami69 Feb 11, 2022 @ 11:28am 
Thank you
CptTwinkie  [author] Feb 11, 2022 @ 3:41am 
@Shinagami69 You don't enter it in the script. You pass it to the script as an argument in the run box. Ideally you add the programmable block to the toolbar and setup the angle when you're doing that.
Shinagami69 Feb 10, 2022 @ 9:11am 
I think I'm missing something. I'm trying to reset a hinge to '0' but I cant see where to enter the angle in the script.
I know I'm being dumb but please help. Ideally I want to use the hinge then hit a button and it will reset back to '0' ready for use next time.
CptTwinkie  [author] Aug 25, 2021 @ 9:17am 
Sorry, steam ate the indentation
CptTwinkie  [author] Aug 25, 2021 @ 9:16am 
Remove line 46

Replace this:
float curAngle = RadiansToDegrees(listHinges .Angle);
if (curAngle != setAngle)
setVelocity = (float)((curAngle < setAngle) ? desiredVelocity: -desiredVelocity);

//Set the appropriate limit
if (setVelocity > 0)
listHinges .UpperLimitRad = DegreesToRadians(setAngle);
else
listHinges .LowerLimitRad = DegreesToRadians(setAngle);

With this:
float curAngle = RadiansToDegrees(listHinges .Angle);
float newAngle = Clamp(curAngle + setAngle, -90, 90);

if (setAngle != 0)
setVelocity = (float)((curAngle < newAngle ) ? desiredVelocity: -desiredVelocity);

//Set the appropriate limit
if (setVelocity > 0)
listHinges .UpperLimitRad = DegreesToRadians(newAngle);
else
listHinges .LowerLimitRad = DegreesToRadians(newAngle);
Hung Aug 19, 2021 @ 6:24pm 
Hey @CptTwinkie
Just started playing SpaceEngineers not to long ago and this script has already been super helpful but i was wondering if you could help me make a small modification for a specific instance.
Id like to use the argument to increment the current angle as opposed to setting the angle directly.
Serathos Apr 9, 2021 @ 7:58am 
Thanks, I managed to figure it out! Turns out you can just handle the Hinge as if it's a rotor and they got a field .Angle, that just wasn't added in the guide I found. After a bit of trial and error, I managed to but it together.
I set it up to run every 100 ticks in the Program() part, apparently there isn't a way to make it even slower without using a Timer Block? A.t.m. I just turn the Programmable Block off, when the drills are not in use.

If anyone else tries this: The angle is in radian, even though it's displayed in degree, so you need to convert them.
CptTwinkie  [author] Apr 7, 2021 @ 12:04pm 
That's kind of tricky. You need a script that will run repeatedly and check the value. You could probably reuse my script. You would need to break execution into two modes, one for setting the rotor settings and one for checking the angle. Then you just have to turn the script repeating on/off on the programming block programmatically. It's clunky but it could work and if you do it carefully it only monitors the rotors that it changed and it only monitors while it needs to. One thing to watch out for is that rotor angles are very precise, so almost never exactly the angle that you set. You'll need to pad a degree or two on both sides of your setting.
Serathos Apr 7, 2021 @ 6:31am 
I'm currently trying to write a script that disables some block automatically once my hinges have reached a certain angle, but I can't find how to get that information inside the program, can you help me with this? I found a guide ( https://steamcommunity.com/sharedfiles/filedetails/?l=german&id=360966557 ), but that doesn't feature Hinges and also misses a field "angle" for the rotor, so I'm wondering if what I want to do is even possible
CptTwinkie  [author] Feb 9, 2021 @ 10:05am 
I'm pretty sure it works with the built in ones assuming they work the same way. I remember testing them and not finding any significant differences. Let me know if anything needs to be adjusted.
orcaman98 Feb 8, 2021 @ 3:22am 
Will this work with stock hinges? If so, can the dependency on mod hinges be removed from Steam?
TestSubject_2519 Apr 1, 2019 @ 3:11pm 
I figured it out, it got stuck because I only had one hinge being used by the script, but I left the extra unused line in (the part I'm supposed to edit). Thanks for the help.
CptTwinkie  [author] Apr 1, 2019 @ 12:37am 
@tadkins320 I just checked it in the latest version and it works fine. Check that your hinge names are correct, the velocity is correct, and you have passed a correct angle in the argument field.
TestSubject_2519 Mar 30, 2019 @ 3:50pm 
I wanted to let you know I ran into an issue with some of your scripts recently. I can use the script to change the hinge angle once then I have to recompile the script for it to work again.

The programmable block gives me this error:

Caught exception during execution
of
script:Object reference not set to
an
instance of an object.
at Program.Main(String angle)
at
Sandbox.Game.Entities.Blocks.My
ProgrammableBlock.<>c__Display
Class26.<ExecutionCode>b__25(My
GridProgram
program)

at
Sandbox.Game.Entities.Blocks.My
ProgrammableBlock.RunSandboxe
dProgramAction(Action`1
action,
String&
response)


Note: The same thing happened with the rotor script and it had the same error. The piston script didn't affect the piston at all from what I could tell and had the same error except (String angle) was (String arg)
mookie1590 Nov 10, 2018 @ 4:13pm 
Update seem to have made it more responsive. less hang ups. Defiantly getting all the kinds ironed out. I'm liking this a lot. Keep up the graet work!

//Never trust users
lol
mookie1590 Nov 10, 2018 @ 12:47pm 
Freaking awesome. Staying ontop of this. I really aprechiate that.
Can't beleive more people don't cry out for this amazing script. It's the only 1 that can control the hinges. The builds people make with these hinges is insane. Like that giant scarab from halo. Absolutly incredible. And your script only makes things that much better,
Hell, I can even make simple hinge doors instead of using rotors. Just a normal massive hinge door with a button panel using your script.
It's the simple things I like.
CptTwinkie  [author] Nov 10, 2018 @ 12:15pm 
UPDATED! There is some incorrect documentation and a couple of methods behaving incorrectly in the API. I was able to work around them.
mookie1590 Nov 5, 2018 @ 7:07pm 
Just played with it a bit. Works like a charm. No more lock ups. Script works fantastic. Now I can work on some of these ideas I had on the back burner.
Thanks a bunch!
mookie1590 Nov 2, 2018 @ 6:23pm 
Awesome my boy. When I get settled in at my new place I'll give this update a try.
Thanks!
CptTwinkie  [author] Oct 30, 2018 @ 4:45pm 
UPDATED!
mookie1590 Oct 20, 2018 @ 3:51pm 
Aw, i see. That would be pretty cool.
Do let me know when you do update this. I don't want this to take to muhc of your time, if it's just for me. Others might be lurking. But I'm the only 1 speaking.
Thanks, man. This is a cool script to go with an all ready cool block mod.
CptTwinkie  [author] Oct 20, 2018 @ 10:48am 
Well locking wasn't an option when I wrote this so it probably needs to be updated. I'll add it to my list of things to do.
mookie1590 Oct 20, 2018 @ 10:26am 
There's this problem I'm having with this. I'm not sure if you're still updating this, or taking sugestions? This is more of s sugestion
I made this little welder grinder ship combo. USed 3 welders and grinders on each side. EAch set of tools has a single tool in the middle with 1 tool on each side conected on hinges. This lets me localise welders into a single point.
decided to try this script. Love it so far. But With my ship I have another hotkey set to lock the kinges so they don't move when the ship moves.
If I hit run an arguemnt while the hinge is lokced. script will lock up and I have to reset it

Also I have the velocoity set at 1. But anything higher the hinges themselves say they wre locked until I lower the velocity. This also locks up your scipt if the hinge locks.
Not sure if you can conjoure up a simple fix. OR add built in controls to lock the hinge after the arguemnt is used.
Love this script so far. I have so many potenial ideas now. Cool stuff, man.
Dark_453 Aug 21, 2018 @ 9:38pm 
Thanks very much buddy, i will check into this when im next in SE, I remember James building his car with this before planets, added in a race track if i remember right.. infact i beleave you wrote this to be able to fine tune that ride :P to drill level off armor blocks :D - well thanks for the update.. talk soon mate.
CptTwinkie  [author] Jul 27, 2018 @ 4:03am 
I checked the script and it was working fine. I decided to give it a little update while I was in there to use arguments and give it a velocity setting. I also added some debugging code for myself. If you're getting errors then I suggest you double check your block names.
Dark_453 Jul 26, 2018 @ 11:49pm 
Hey Mr Twinkie, Hopes your well sir, Could you maybe update this so it works again. im getting some nasty errors while trying to complie it.. at least since the mp update. -(digi updated the Hinges)- so gonna try building with em again. your script is VERY usefull for sorting that out :D
CptTwinkie  [author] Mar 26, 2015 @ 6:11am 
I could make a video right now but I don't see why. All it does is make a hinge rotate to a specific angle. It's basically a way of making a pre-set that you can assign to a button or timer.
Mornedhel Mar 25, 2015 @ 8:29am 
Sounds like a very usefull script! Could you eventually make a video of the results?