DomDiaemus Posted November 1, 2014 Share Posted November 1, 2014 I'm looking for a simple script which put my satelite heading prograte towards the sun all the time. Anyone give me some pointers?This might helpSET sp TO sun:position - body:position.LOCK STEERING TO sp. Link to comment Share on other sites More sharing options...
GabeTeuton Posted November 1, 2014 Share Posted November 1, 2014 (edited) Sorry to be bothering once again... I'm still developing a better autopilot system and well i made some progress but now i'm stuck...the main objective of this script is to keep gaining pitch up until the vertical speed is 1 m/s, then it should stop gaining vertical speed by making the vertical acceleration 0, which means it will stop adding pitch when vertical aceleration is 0, and then it will stay there until said otherwise...I've got this vertical acceleration script=CLEARSCREEN.UNTIL 1 < 0 {SET T1 TO MISSIONTIME. SET VS1 TO VERTICALSPEED. WAIT 0.1. SET T2 TO MISSIONTIME. SET VS2 TO VERTICALSPEED.SET VA TO (( VS2 - VS1 ) / ( T2 - T1 )).PRINT "ACELERACION VERTICAL= " + VA AT (0,10).}.(This code will tell me a very accurate vertical acceleration, now there's an until there to make the program recalculate it every time...)So far it works, by itself...Now how do I tell the autopilot to keep adding pitch until Verticalspeed = 1, in which case will have to stop adding pitch or even removing pitch until VA = 0?So far i've got his=CLEARSCREEN.SET PU TO 0.SET SHIP:CONTROL:PITCH TO "PU".UNTIL ALT:RADAR < 0 { SET T1 TO MISSIONTIME. SET VS1 TO VERTICALSPEED. WAIT 0.1. SET T2 TO MISSIONTIME. SET VS2 TO VERTICALSPEED.SET VA TO (( VS2 - VS1 ) / ( T2 - T1 )).PRINT "ACELERACION VERTICAL= " + VA AT (0,10).PRINT PU AT (0,5).}.IF VERTICALSPEED < 1 {SET PU TO PU + 0.0001.} ELSE UNTIL VA = 0 {SET SHIP:CONTROL:PITCH TO PU - 0.0001.}.(but this code doensn't work, it never gets to the IF statement, and if i put the if above the until, then it never gets to the until... so i don't know if the script is adding pitch... my head is about to explode haha.-I also tried using when and also until instead of IF, can't make it work either)!Ideas?TIAPS= this goal i'm trying to achieve now is an intermediate goal, as after this is done i'll set everything to happen around X altitude... but first this bit, then we'll see...! Edited November 1, 2014 by GabeTeuton Link to comment Share on other sites More sharing options...
Dunbaratu Posted November 2, 2014 Share Posted November 2, 2014 UNTIL ALT:RADAR < 0 { Uhm... how on earth can that EVER be true? For it to be true, your ship would have to be underground. Link to comment Share on other sites More sharing options...
Dunbaratu Posted November 2, 2014 Share Posted November 2, 2014 @any of the devs, i usually use notepad ++ to mess with most games files, and i just realized there's a way to load a "languages", it asks me for xlm file, is there such a file for the language kOS uses? Will loading such a file, if it exists, help not make mistakes when coding?It doesn't exist but maybe could be made.One thing I'd love to do some day is to have kOS spit out a config file that describes the keywords, begin/end pairings, and predefined suffixes and variables, in some sort of format that it would be easy for people to have code read it and spit out whatever syntax def format their preferred editor uses.What has made it impossible up until now has been that the majority of that information is built on the fly at runtime. Some edits we did for 0.15 do push things in a direction that might make this posisble some day.But in the meantime the only way to get syntax highlighting in editors is to write the syntax highlight rules manually. Link to comment Share on other sites More sharing options...
GabeTeuton Posted November 2, 2014 Share Posted November 2, 2014 Uhm... how on earth can that EVER be true? For it to be true, your ship would have to be underground.It's like 1 < 0, i use that to make the loop go for ever, as radar altitude in terms of ksp will never go < 0, so the VA keeps being calculated, is there a "legal" way to make a loop go forever? Link to comment Share on other sites More sharing options...
Dunbaratu Posted November 2, 2014 Share Posted November 2, 2014 It's like 1 < 0, i use that to make the loop go for ever, as radar altitude in terms of ksp will never go < 0, so the VA keeps being calculated, is there a "legal" way to make a loop go forever?But your complaint was that it never gets to the IF statement after the loop. If you intended the loop to last forever, then of course it won't get to the "IF". By the way you can just do this: UNTIL FALSE { stuff }. Link to comment Share on other sites More sharing options...
GabeTeuton Posted November 2, 2014 Share Posted November 2, 2014 But your complaint was that it never gets to the IF statement after the loop. If you intended the loop to last forever, then of course it won't get to the "IF". By the way you can just do this: UNTIL FALSE { stuff }.Logic just knocked my door and slap me in the butt... what a stupid question i made when it was as easy as if the loops never ends then it will never continue with the rest of the program xD!so UNTIL FALSE, what does it mean? when is FALSE? or when FALSE happens? (i just looked in the 2 wikis i usually refer to, the first one being the one hosted in github and didn't find anything...)should it be=CLEARSCREEN.UNTIL FALSE {SET T1 TO MISSIONTIME.SET VS1 TO VERTICALSPEED.WAIT 0.1.SET T2 TO MISSIONTIME.SET VS2 TO VERTICALSPEED.SET VA TO (( VS2 - VS1 ) / ( T2 - T1 )). PRINT "ACELERACION VERTICAL= " + VA AT (0,10). }.Still would like to know how it works if it doesn't bother you!thank you, and i apologise for being so stupid, how did i miss that...???? so logical now haha, i feel so bad! Link to comment Share on other sites More sharing options...
Dunbaratu Posted November 2, 2014 Share Posted November 2, 2014 Still would like to know how it works if it doesn't bother you!Try this:set x to 3.print x > 5.print x < 5.When you say PRINT X > 5, it says "False". When you say PRINT X < 5, it says "True".That's because False and True are actual values an expression can "hold", if it's a boolean check expression.You can bypass the actual checking and just SAY FALSE or TRUE, meaning "act as if there is a boolean check here that was TRUE" or "act as if there is a boolean check here that was false". Link to comment Share on other sites More sharing options...
GabeTeuton Posted November 2, 2014 Share Posted November 2, 2014 Try this:set x to 3.print x > 5.print x < 5.When you say PRINT X > 5, it says "False". When you say PRINT X < 5, it says "True".That's because False and True are actual values an expression can "hold", if it's a boolean check expression.You can bypass the actual checking and just SAY FALSE or TRUE, meaning "act as if there is a boolean check here that was TRUE" or "act as if there is a boolean check here that was false".Quite interesting, and quite useful as well... i'll try that and keep the development going, and keep you guys posted, i will certainly need more help! Once again thank you Steven! Link to comment Share on other sites More sharing options...
Camacha Posted November 2, 2014 Share Posted November 2, 2014 did you just call me fat!!! im going to just remove the boot feature!!!!!I have had some weird things happen with boot, the latest being that I could not get the units to not run the script, no matter what I did in the VAB. Even removing and replacing all the units would, upon load, yield the script running. Unfortunately my KSP installation is down at the moment, but I intend to toy with that a little more, because it is not working like it should for sure.Maybe that some keyboard ballet will burn those Halloween calories Link to comment Share on other sites More sharing options...
Camacha Posted November 2, 2014 Share Posted November 2, 2014 "legal" way to make a loop go forever?Just using until 0 used to be enough, as is an (informal?) standard. Not sure that still works, I cannot test it, but I assume it does.Edit: opening the thread a page early, missing Steven's reply. It's basically the same thing. Link to comment Share on other sites More sharing options...
VFB1210 Posted November 2, 2014 Share Posted November 2, 2014 Is there some reason you can't use your own flag value for this?Forgive me if I am incorrect, but wouldn't trying to create my own flag value end up something like this?DECLARE RUNSTEPSET RUNSTEP TO 0IF RUNSTEP = 0 { //initialization stuff here RUNSTEP++}ELSE { //program stuff here RUNSTEP++}Which would cause the program to declare the variable, set it to zero, enter the "true" part of the if loop, do initialization stuff, increment RUNSTEP, then go back to the top and set RUNSTEP back to 0 again, and repeat ad infinitum. Or maybe I'm just not thinking it through enough. It has to be possible on some level at least I suppose, or else the first() function I mentioned wouldn't exist. Link to comment Share on other sites More sharing options...
Camacha Posted November 2, 2014 Share Posted November 2, 2014 What does the ++ do? I have been out for a while, I am not familiar with this. Link to comment Share on other sites More sharing options...
Dunbaratu Posted November 2, 2014 Share Posted November 2, 2014 What does the ++ do? I have been out for a while, I am not familiar with this.In lots of languages, "++" means "increment this by one". foo++ is shorthand for foo = foo + 1, as is ++foo (putting it on either side of the variable name). There is a slight difference between putting it on the left or on the right, but that detail isn't worth getting into right now. It first appeared in K&R C and lots of other languages have borrowed it since then.BUT..... Kerboscript isn't one of them. I'm pretty sure that doesn't work in kerboscript. Link to comment Share on other sites More sharing options...
Camacha Posted November 2, 2014 Share Posted November 2, 2014 In lots of languages, "++" means "increment this by one". foo++ is shorthand for foo = foo + 1, as is ++foo (putting it on either side of the variable name). There is a slight difference between putting it on the left or on the right, but that detail isn't worth getting into right now. It first appeared in K&R C and lots of other languages have borrowed it since then.It seems strange to translate ++ as one, rather than just a + and making ++ translate as 2 or 10, though I am sure there is a good and lengthy technical explanation for that. Thanks for the info! Link to comment Share on other sites More sharing options...
Cairan Posted November 2, 2014 Share Posted November 2, 2014 (edited) It all comes down to parsing...If you have A + B, the compiler/interpreter looks at it and parses it to:Operand A is augmented by Operand B.Now when you have the "addition" operator, it expects a second operand ... If you call A + ... and nothing else, then it fails because it expected a value to increment A from... The trick is then to provide a special operand, the second + ...A++ then turns out to be Operand A is augmented + ... which has a special meaning of 1 (ie. incrementation). You also have other nice syntax tricks such asA+= 12 which means Operand A is equal to Operand A augmented by Value 12. ... And then, you can also overload operators, but that's a whole different can of worms While I'm on the subject of variables and operations, in a galaxy far far away in a release a long long time from now, would it be possible to convert strings to LIST()?Say I wanted to do this, like we can in C, PHP, Python, etc...SET teststring to "ABCDEF".// [...] later on...SET option TO teststring[4].PRINT "The option is" + option.The option is E PRINT teststring.ABCDEFDon't even consider it a serious request, it's just something I find myself wishing for quite often, but there's always work arounds... like this:SET teststring TO LIST().SET teststring:ADD TO "A".SET teststring:ADD TO "B".SET teststring:ADD TO "C".SET teststring:ADD TO "D".SET teststring:ADD TO "E".SET teststring:ADD TO "F".SET option TO teststring[4].PRINT "The option is" + option.The option is E SET szout TO "".FOR chr IN teststring { SET szout TO szout+chr.}PRINT szout.ABCDEF. Edited November 2, 2014 by Cairan Link to comment Share on other sites More sharing options...
Camacha Posted November 2, 2014 Share Posted November 2, 2014 Now when you have the "addition" operator, it expects a second operand ... If you call A + ... and nothing else, then it fails because it expected a value to increment A from... The trick is then to provide a special operand, the second + ...To me, it seems there is nothing standing in the way of making a single + without operand translate as +1 (binary or decimal). Making the second plus count as one seems as arbitrary, or actually even more so. Link to comment Share on other sites More sharing options...
VFB1210 Posted November 2, 2014 Share Posted November 2, 2014 (edited) BUT..... Kerboscript isn't one of them. I'm pretty sure that doesn't work in kerboscript.Right, I forgot that ++ isn't in Kerboscript. Regardless, is there a way to get around the problem presented with creating your own flag value?Also, Camacha, it seems to me that the ++ notation is advantageous because it clearly distinguishes that the variable to be incremented is actually supposed to be incremented, and not that the programmer mistakenly omitted the second operand. Also, if you do not include a specific operand, wouldn't the compiler simply try to interpret the next thing after the operator as the second operand? Example:...program.DoStuff()Foo++Bar++program.DoMoreStuff()...Here, the character following the operator is the second plus sign, which has been assigned the value one in this context. The compiler sees this plus sign as the second operand, and acts accordingly. But consider the following example:...program.DoStuff()Foo+Bar+program.DoMoreStuff()...Most languages would interpret this in the same way as this:...program.DoStuff()Foo+Bar+program.DoMoreStuff()...Thus, the program would attempt to sum the values of Foo, Bar, and whatever number program.DoMoreStuff() returned, if it returned anything at all, which is obviously not the intended behavior. Edited November 2, 2014 by VFB1210 Link to comment Share on other sites More sharing options...
mideg Posted November 2, 2014 Share Posted November 2, 2014 DECLARE RUNSTEPSET RUNSTEP TO 0IF RUNSTEP = 0 { //initialization stuff here RUNSTEP = RUNSTEP + 1;}ELSE { //program stuff here RUNSTEP = RUNSTEP + 1;}Which would cause the program to declare the variable, set it to zero, enter the "true" part of the if loop, do initialization stuff, increment RUNSTEP, then go back to the top and set RUNSTEP back to 0 again, and repeat ad infinitum. Or maybe I'm just not thinking it through enough. It has to be possible on some level at least I suppose, or else the first() function I mentioned wouldn't exist.I don't know how Kerboscript initializes variables. IF they do reliably initialize variables, for example always letting them be FALSE or 0 at first, this could work. Another possibility would be something like IFNDEF known in some languages or rather, precompilers, I think. IFNDEF (read: IF NOT DEFINED) enables you to write a conditional code segment tha only executes if the variable followed by IFNDEF is not defined. Example:IFNDEF RUNSTEP THEN { DECLARE RUNSTEP SET RUNSTEP TO 0}IF RUNSTEP = 0 { //initialization stuff here RUNSTEP = RUNSTEP + 1;}ELSE { //program stuff here RUNSTEP = RUNSTEP + 1;}IFNDEF is probably not compatible with Kerboscript, though. Maybe Kerboscript does set all variables to value 0 when declaring them? Link to comment Share on other sites More sharing options...
VFB1210 Posted November 2, 2014 Share Posted November 2, 2014 I never thought about that. I suppose if all variables are set to 0 when declared it would be pretty trivial. Or if they are given no value at all, wouldn't they be null until otherwise specified? If that is the case, the following might be possible:IF RUNSTEP = NULL { DECLARE RUNSTEP SET RUNSTEP TO 0}IF RUNSTEP = 0 { //initialization stuff here RUNSTEP = RUNSTEP + 1;}ELSE { //program stuff here RUNSTEP = RUNSTEP + 1;}Although I guess that is almost functionally identical to IFNDEF. Link to comment Share on other sites More sharing options...
falcoiii Posted November 2, 2014 Share Posted November 2, 2014 I am having a problem with a main script calling another launch script. I have other scripts calling each other, but these two always have the same problem. Last line in the launch script is a print "in orbit". and the next line in the main script is a print "finished launching". ...In orbitArgument is out of rangeparameter name: indexAt firstmission on 1, line 1copy dlaunch from 0. ^Called from mainmission on 1, line 19run firstmission.^... any idea how I can debug this? Link to comment Share on other sites More sharing options...
Trewor007 Posted November 2, 2014 Share Posted November 2, 2014 falcoiiiWithout the source code we cant tell You very much.my guess is that after lunching Your 1 code executed properly and went back to the main program.and then the mail program look up some condition for choosing the next program. And the problem is or in that condition or the main program is looking for 2 sub program in a wrong volume. but that's all just speculation. Link to comment Share on other sites More sharing options...
GabeTeuton Posted November 2, 2014 Share Posted November 2, 2014 (edited) Well I reached my limit of understanding... after trying several different combinations of commands and thinking of ways to do this i just can't make it work... so i'm after advice or something, if anyone is interested... To get this i made that flow chart or i guess i did to help you guys understand what i'm trying to do in a very visual way... i hope it helps...Thank you!(i can make it work manually, just adjust the pitch by a very small amount until the VS and VA is 0 (this i'll do when trim is released)... but i would like it to be automated, as an autopilot, if possible) Edited November 2, 2014 by GabeTeuton Link to comment Share on other sites More sharing options...
Dunbaratu Posted November 2, 2014 Share Posted November 2, 2014 I never thought about that. I suppose if all variables are set to 0 when declared it would be pretty trivial.The reason why an IFNDEF is useful is that for many data types, there is no such thing as an impossible value that doesn't actually ever happen in normal operations. You need to be able to tell the difference between "this number is zero because it was never defined" from "this number is zero because it was SET to zero."IMO, an IFNDEF would be a useful thing to add to kOS. Link to comment Share on other sites More sharing options...
Diazo Posted November 2, 2014 Share Posted November 2, 2014 I don't have anything specific to point out in the flowchart two posts ago, but I'm wondering if you are looking at enough variables.Notably, that flowchart behaves no differently if you are 15m or 1500m above 5000m altitude.While it is only vaguely similar, I had to include that in the math for my vertical velocity mod. (I was controlling engine thrust to change vertical speed as compared to you adjusting pitch to change vertical speed.)How fine control do you have? Can you do something like:Desired vertical speed = (Desired altitude - Vessel altitude)/2; //so desired speed is half the distance to target, negative if above target, positive if belowIf(Current Vertical Speed > Desired Vert Speed) then Pitch Down;If(Current Vertical Speed < Desired Vert Speed) then Pitch Up;That way as you approach 5000m, the desired speed will decrease automatically and you should damp out any sort of bounce going on from blowing past 5000m at a full 10m/s.You would have to add a maximum as well, without it if you are really far off, the code above would not stop trying to pitch down until you were pointing straight down.D. Link to comment Share on other sites More sharing options...
Recommended Posts