Jump to content

KOS Help. Please. I beg you.


DerGolgo

Recommended Posts

Hi,

I'm fairly new here and I know it's pretty presumptuous of a noob stepping right in and asking for help.
But I'm going quite insane. I have tried flying with keyboard commands and, no surprise, I suck at it.
For three days now, I've been desperately trying to write a KOS script that does a few very simple things. Not even involving the ship changing orientation a single time. Really just straight up and straight down.
The ship CAN do all the things, if I play around with MechJeb to assist keyboard control, it all works (within the limits of my utterly rubbish control abilities).
But there is one specific little item holding me up. That had me write and rewrite my script and try it out dozens, possibly a full one-hundred times.

The problem: I want it to drop the SRBs when those are empty.
I've given all the SRB's a name tag and have desperately tried all (and I do mean ALL) combinations of my name tag, the enumerator I stuffed with all the tagged parts, SHIP, SOLIDFUEL and AMOUNT.
I've also tried out checking for FLAMEOUT.
Nuffin.

I've tried the little  "THESE ARE ALL THE RESOURCES ON THE SHIP:". script snippet from documentation site on Github. That works fine and lists a resource "SolidFuel". 
Yet when I ask the terminal to PRINT SHIP:SOLIDFUEL:AMOUNT., I get an error that AMOUNT is an unknown variable. When I stop the line at SOLIDFUEL., I get the number 1436. So that works.
Yet when I try PRINT SHIP:PARTSTAGGED("booster"):SOLIDFUEL., I'm told SOLIDFUEL is an unknown variable. The parts in question ARE tagged "booster", of course.

I don't want anyone to go and write me a whole script, of course.
Just an example how I can get the SolidFuel from a specific set of parts and a little explanation would be absolutely lovely.

Please?

I suspect I have a fundamental misunderstanding of the entire syntax and structure. But neither going through the GitHub documentation nor trial and/or error have enlightened me.

Link to comment
Share on other sites

> PRINT SHIP:PARTSTAGGED("booster"):SOLIDFUEL

Two problems with that:

1. The :SOLIDFUEL suffix is only on the entire vessel level, not on the level of a single part.  (It totally could be and maybe we should add that, but right now it's not).

2. PARTSTAGGED is plural for a reason - because you're allowed to give the same tag name to more than one part, the suffix is designed to return a LIST of parts, not a single part.  If you want to look at the first part in the list, put a '[0]' at the end of it.  If you want to look at all the parts it returns make a FOR loop like so:  FOR P in SHIP:PARTSTAGGED("booster") { // do something with P here. }

try this:
 

local I_SHOULD_STAGE is False.
FOR P in SHIP:PARTSTAGGED("booster") {
  if P:HASSUFFIX("FLAMEOUT") and P:FLAMEOUT { // Note the use of short-circuit boolean protection here.
    print "I have a flamed out booster, I will stage".
    set I_SHOULD_STAGE to False.
  }
}
if I_SHOULD_STAGE { stage. }

 

Link to comment
Share on other sites

Thank you!

I tried it verbatim at first and, when that didn't work, changed the attribute

set I_SHOULD_STAGE to False.

to true and then, hurrah, it works! Thanks for demonstrating the importance of the attributes!
But I found it only works if I put your snippet right in the chronological order.

When I try this with I_SHOULD_STAGE as a global variable, and put the rest of it in a little "RUNMODE" loop, it just gets stuck there, though.
My plan had been to make a bunch of these RUNMODE loops, at the top of the script, and then have the chronological script just be along the lines of:

SET RUNMODE TO 2.
WAIT UNTIL I_SHOULD_STAGE=TRUE.
STAGE.

The first thing my little RUNMODE loop does is print the runmode that's going. That happens. But then, nothing.
I don't want to impose, obviously. And whatever mistake I'm making is, indubitably, something trivial only an utterly ignorant noob would get wrong. I am NOOB:IGNORANT:MAG = UTTERLY, no question. I haven't done any programming since object-oriented C before I failed out of engineering school over a decade ago, have since lost most of my eyesight, which possibly may be how I missed an oft repeated, bold, underlined instruction in the documentation on GITHUB. I can write an entire novel, as you see, or a pretty vast script, though, it's just the reading of unfamiliar texts that's my problem.

These are, of course, not your nor the rest of the community's problems and I seriously don't want to impose.
But ANY hints at what I'm krakensing up would be exceptionally appreciated!

Edited by DerGolgo
Link to comment
Share on other sites

8 hours ago, DerGolgo said:

 


SET RUNMODE TO 2.
WAIT UNTIL I_SHOULD_STAGE=TRUE.
STAGE.

 

The problem is that the code needs to be run in order for I_SHOULD_STAGE to ever get set.  The WAIT UNTIL line is going to sit there and never run the loop that looks for the stage condition.

You could make it a function that returns a boolean value, then call that function in the WAIT statement.

FUNCTION partlist_flameout {
  parameter part_list. // pass in a LIST() of parts to check.

  FOR P in part_list {
    if P:HASSUFFIX("FLAMEOUT") and P:FLAMEOUT { // Note the use of short-circuit boolean protection here.
      return true.
    }
  }
  return false.
}


// Then later when you try to use it:
local boosters is SHIP:PARTSTAGGED("booster").
SET RUNMODE TO 2.
WAIT UNTIL partlist_flameout(boosters).
STAGE.

The reason I suggested making it just operate on a LIST you pass in, is that it is a bit more efficient that way because it doesn't have to keep re-searching for the part tags - it only builds the list once.  Also, this makes it generically re-usable with other part lists you might want to use it on later.

 

Link to comment
Share on other sites

Thank you!

I'll play around with this.
I'd appreciate being corrected, but what I will try is:

That FUNCTION bit at the top.
Then, either in the RUNMODE 2, or chronologically in the script after defining "local boosters" it should be:

IF partlist_flameout(boosters) {STAGE.}


or possible
 

IF partlist_flameout(boosters)=TRUE {STAGE.}

Thanks!!

Link to comment
Share on other sites

Okay, I've tried this now, I think I've got it.

I know I'm getting repetitive, but thank you!

There are far too many online "communities" where any nooby question is met with things along the lines of "anyone who has to ask that shouldn't be doing this"  and "stop bothering the grownups". Delightfully refreshing to find one that isn't!

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...