Jump to content

MechJeb Autom8 Scripts Megathread


r4m0n

Recommended Posts

I have scripts working and will post a few when they are polished. Am I able to do

print vessel.altitudeASL

and 'report' to the window the vessel's current height? How would I do this (assuming it's even possible).

If you print something that isn't a string, you need to enclose the argument in ():

print(vessel.altitudeASL)

Link to comment
Share on other sites

Thanks for that - the next obvious question is string concatenation. :) print "craft altitude is now " & (vessel.altitudeASL)

(I haven't tried that btw!)

Is it possible to expose total fuel on board or total fuel in current stage? Loving the scripts. :)

Link to comment
Share on other sites

Thanks for that - the next obvious question is string concatenation. :) print "craft altitude is now " & (vessel.altitudeASL)

(I haven't tried that btw!)

Is it possible to expose total fuel on board or total fuel in current stage? Loving the scripts. :)

String concatenation operator is "..", example:

print("Altitude is "..vessel.altitudeASL)

No functions for total fuel yet afaik, you need to find and access the single tanks to get fuel amounts.

Link to comment
Share on other sites

I'm having a problem with the mun script, i have named it to just mun and when i enter dofile "(mun)" it says:

ParserException: Code has syntax errors:

Line 1, Col 8 '"': Failed to parse Letter of Name.

Line 1, Col 8 '"': Failed to parse Name of VarName.

Line 1, Col 8 '"': Failed to parse 'nil' of NilLiteral.

Line 1, Col 8 '"': Failed to parse Text of BoolLiteral.

Line 1, Col 8 '"': Failed to parse '0'...'9' of Digit.

Line 2, Col 1 : Failed to parse '\"' of StringLiteral.

Line 1, Col 8 '"': Failed to parse Name of VariableArg.

Line 1, Col 8 '"': Failed to parse Letter of Name.

Line 1, Col 8 '"': Failed to parse Name of VarName.

Line 1, Col 8 '"': Failed to parse firstTerm of OperatorExpr.

Line 1, Col 8 '"': Failed to parse 'nil' of NilLiteral.

Line 1, Col 8 '"': Failed to parse Text of BoolLiteral.

Line 1, Col 8 '"': Failed to parse '0'...'9' of Digit.

Line 2, Col 1 : Failed to parse '\"' of StringLiteral.

Line 1, Col 8 '"': Failed to parse Name of VariableArg.

Line 1, Col 8 '"': Failed to parse Letter of Name.

Line 1, Col 8 '"': Failed to parse Name of VarName.

Line 1, Col 8 '"': Failed to parse Expr of ExprStmt.

Line 1, Col 8 '"': Failed to parse remaining input.

What's wrong? :(

Link to comment
Share on other sites

Here are four scripts, all basically modifications of R4m0n's FlyMeToTheMun.

With <a href="http://pastebin.com/C4nDeKEk">KMun</a> I changed the name, typing in FlyMeToTheMun (capitalization required) got real old, real fast. I added a variable to input Kerbin Orbit Altitude and it adjusts Pe (one time using the original, it warped me into Mun).

<a href="http://pastebin.com/VQJrQXgg">KMin</a> was just the next logical step. Lands on Minmus.

<a href="http://pastebin.com/82iTeTrW">KMunO</a> gets you into Mun orbit at the input altitude.

I'll let you figure out for yourself what <a href="http://pastebin.com/Qfnp6YVw">KMinO</a> might do.

To use, open autom8 and type in dofile("filename") then click execute.

This will give you "usage". Hopefully that is clear. Capitalization and spaces are required. Click execute.

<font color="red">Warning:</font>

On both Minmus scripts insure that you will not be caught in Mun's SOI. If you don't know how to do that, from the launch pad go to the orbital map (default M) and if necessary time warp until Mun is out of the way. Strange things happen if you are caught in Mun's SOI on the way to Minmus.

I'm also attaching a zip file (because that's what I know) that you can just unzip into KSP\plugindata\mumechlib.

Finally, if the scripts aren't working for you, try cleaning up your system. After uncountable times running and rerunning the scripts to make sure they worked the way I wanted, one more try didn't work. WTF! I ran <a href="http://www.wisecleaner.com/wisecare365.html">Wise Care 365</a> , defraged and rebooted and the script magically worked again.

The haters are going to love me now.

<font color="Orange">Edits</font>

Cleaned up some code.

Added error catch.

Added immediate landing option, example - KMun(75,"il","il"), quotes are required.

And, after having my ship topple over for no apparent reason, added stabilization.

Edited by Jontu
Update zip file
Link to comment
Share on other sites

A few questions:

First, is there a better documentation link? It seems to be missing the concatenation operator, as well as things like the wait() function (i.e. wait(function() return (vessel.altitudeASL <= 75000) end ), per the Shuttle Autopilot Library by olex. In particular, Wait and Warp to seem to be absolutely critical, and I'd like to know how to control waits and warps other than Pe, Ap, and Sol.

In particular, how can I Warp to just after a certain point in orbit (say, the point as far from KSP as is possible?

FlyMeToTheMun is a good start, but when I tried FlyMeToTheMun(35,35), and once in Munar orbit, the LandTo doesn't appear to be warping ("Cannot warp faster than 1x while the ship is under acceleration"). My orbit is Pe 200836 Ap 200986km Inclination 1.25 Semimajor Axis 400.870km, LAN 145.36, LPe <varies wildly). Stock parts except for MechJeb 1m on top of the 1 kerbal capsule, plenty of fuel left, and I'm at the "Landing" step. EDIT: Just as I posted, my rocket apparently hit the right orbital point, and began its inclination change burn. Still, I'd much rather it have "cut acceleration" and warped.

Edited by Nadrek
Link to comment
Share on other sites

How is meaning of this numbers /mechjeb.attitudeTo({0,0,0,0}, "ORBIT")/

If i put anything to second place example- /mechjeb.attitudeTo({0,0.2,0,0}, "ORBIT")/ shutle aim straigth up.

I want set somethhing about 20 degrees pitch.

Link to comment
Share on other sites

Thank you for the reference; if I'd seen that Lua guide in the Autom8 wiki, I would have read it.

Is there a trick to using C functions inside Lua with Autom8, per:

http://stackoverflow.com/questions/1034334/easiest-way-to-make-lua-script-wait-pause-sleep-block-for-a-few-seconds

?

You can't use C functions is the Lua console directly. If all you want to do is to pause the script for a given time, use the provided wait(ms) function.

How is meaning of this numbers /mechjeb.attitudeTo({0,0,0,0}, "ORBIT")/

If i put anything to second place example- /mechjeb.attitudeTo({0,0.2,0,0}, "ORBIT")/ shutle aim straigth up.

I want set somethhing about 20 degrees pitch.

It's a quaternion, look it up here: http://en.wikipedia.org/wiki/Quaternion

Setting them manually is tricky and is actually not recommended. For a manual pitch setting, you cann pass a 3-dimensional vector instead of the quaternion - I only used a direct quaternion there because I needed to turn the ship wings-level, too.

Link to comment
Share on other sites

I'm not gonna lie but non of this ever works for me can someone give me a step by step on flymetothemun!

There is a step-by-step in the first post. What exactly doesn't work for you? We can't help you not knowing the issue.

Link to comment
Share on other sites

I try it but not work for Ascent Autopilot, and even not work mechjeb.stage() when ascent autopilot is active /i try power up main engine during fligth/.

But is not big problem even if that working i cant deactivate jet engines by autom8 so there is still something needed control manualy.

Link to comment
Share on other sites

My script file is attached for those that like my methods. Can't say I did it all on my own though.

File is v1.0 and says so inside the script. File has a .txt name so the forum can accept the attachment. Save to PC and remove the .txt.

type

dofile("orbitops")

full instructions displayed.

Link to comment
Share on other sites

so if I enter the line

mechjeb.attitudeTo({0,0,0}, "ORBIT")

where exactly will that take me to and does it matter on my current soi? Is 0,0,0 relative or absolute? Relative to what?

The heading you enter is always relative, and it's relative to the second argument, in this case "ORBIT" meaning relative to your orbital prograde heading. Check the wiki for other possible values - you can enter headings relative to orbit, surface, absolute world coordinate system, target vessel/body, and a few more things.

Link to comment
Share on other sites

> dofile(''Shuttle.lua'')

ParserException: Code has syntax errors:

Line 1, Col 10 'S': Failed to parse ')' of GroupExpr.

Line 1, Col 7 '(': Failed to parse Letter of Name.

Line 1, Col 7 '(': Failed to parse Name of VarName.

Line 1, Col 7 '(': Failed to parse 'nil' of NilLiteral.

Line 1, Col 7 '(': Failed to parse Text of BoolLiteral.

Line 1, Col 7 '(': Failed to parse '0'...'9' of Digit.

Line 1, Col 7 '(': Failed to parse Name of VariableArg.

Line 1, Col 10 'S': Failed to parse ')' of GroupExpr.

Line 1, Col 7 '(': Failed to parse Letter of Name.

Line 1, Col 7 '(': Failed to parse Name of VarName.

Line 1, Col 7 '(': Failed to parse firstTerm of OperatorExpr.

Line 1, Col 7 '(': Failed to parse 'nil' of NilLiteral.

Line 1, Col 7 '(': Failed to parse Text of BoolLiteral.

Line 1, Col 7 '(': Failed to parse '0'...'9' of Digit.

Line 1, Col 7 '(': Failed to parse Name of VariableArg.

Line 1, Col 10 'S': Failed to parse ')' of GroupExpr.

Line 1, Col 7 '(': Failed to parse Letter of Name.

Line 1, Col 7 '(': Failed to parse Name of VarName.

Line 1, Col 7 '(': Failed to parse Expr of ExprStmt.

Line 1, Col 7 '(': Failed to parse remaining input.

When trying the space land script, could anyone help :D

Edited by sal_vager
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...