Jump to content

kOS Help?


Recommended Posts

I wrote these two programs as a test launcher for the kOS mod. I'm in version 0.24.2, and as far as I know this is not a bug.

circularize


//Circularization Program.
//
//declare parameter gparam.
//declare parameter timetoapo.
//declare parameter altitude.
//declare parameter apospeed.
//declare parameter radiusofbody.

wait 1.

set gparam to 3531600000000.

set altitude to ship:apoapsis.

set timetoapo to eta:apoapsis.

set apospeed to velocityat(ship,time:seconds+timetoapo).

set radiusofbody to 600000.

set absalt to (altitude + radiusofbody).

set velorbit to sqrt((gparam)/absalt).

//set velremaining to (velorbit - apospeed).

if (velorbit - apospeed) > 5 {

set burnnode to node((time:seconds + timetoapo),velremaining,0,0).
add burnnode.

}.

wait 1.

kostestlaunch


//KOS Test Launcher
//
set kerbinGParam to 3531600000000.
set kerbinRadius to 600000.
set targetorbit to 85000.
set completion to False.
set burn1 to False.
set burn2 to False.
set countdown to 10.

print "Counting down:".
until countdown = 0{
print "..." + countdown.
if countdown = 5{
print "Automatic Steering Systems Engaged.".
lock steering to heading(90,90).
}.
if countdown = 3{
print "100% Throttle Confirmed".
lock throttle to 1.
}.
if countdown = 1{
print "Engine Ignition Sequence Start".
stage.
}.
set countdown to countdown - 1.
wait 1. //pause for 1 second
}.

print "ZERO: RELEASING CLAMPS...".
stage.
wait 1.

when stage:liquidfuel < 0.001 then {
print "Liquid Fuel Depleted. Attempting to stage.".
stage.
preserve.
}.

when ship:altitude > 6000 then {
print "Initiating Gravity Turn. Applying torque.".
lock steering to heading(90,45).
}.

when ship:apoapsis > 40000 then {
print "Finalizing Gravity Turn. Applying torque.".
lock steering to heading(90,0).
}.

when ship:apoapsis > 85000 then {
print "Apoapsis target achieved. Engine cutoff.".
lock throttle to 0.
unlock all.
set burn1 to True.
}.

when ship:altitude > 60000 then {
toggle panels. //should deploy solar panels at 60 km
}.

when burn1 = True and burn2 = False and ship:apoapsis < 83000 then {
lock throttle to 0.5.
set burn2 to True.
preserve.
}.

when burn1 = True and burn2 = True and ship:apoapsis > 85000 then {
lock throttle to 0.
set burn2 to False.
preserve.
}.

until ship:altitude > 70000{}.

set timetoapo to eta:apoapsis.
set apospeed to velocityat(ship,time:seconds+timetoapo).
//run circularize(kerbingparam,timetoapo,ship:apoapsis,apospeed,kerbinradius).
run circularize.

wait 1.
print "Program Termination.".

It says "Object reference not set to an instance of an object" when it tries to run the circularization program, either manually or when it is called with kostestlaunch.

What am I doing wrong?

Edited by Starwhip
Link to comment
Share on other sites

I haven't used KOS for a while but it looks like the period after your brackets should not be there if you have periods on the internal lines. At least, that's how C works. If it's not that, then you're trying to reference a structure incorrectly but I can't tell which one.

Link to comment
Share on other sites

Dunno about kOS .... but in most programming languages the condition that schould be evaluated for an if-statement has to be enclosed in brackets

i.e. IF (condition) { ... }

similarly for multiple conditions:

IF ((condition 1) AND|OR (condition 2) AND|OR ... ) { ... }

Link to comment
Share on other sites

SET X TO 1.

IF X = 1 { PRINT "X equals one.". }. // Prints "X equals one."

IF X > 10 { PRINT "X is greater than ten.". }. // Does nothing

//

// IF-ELSE structure:

IF X > 10 { PRINT "X is large". } ELSE { PRINT "X is small". }.

//

// An if-else ladder:

IF X = 0 {

PRINT "zero".

} ELSE IF X < 0 {

PRINT "negative".

} ELSE {

PRINT "positive".

}.

Although a period (.) is usally optional after the end of a set of curly braces like so:

{ }.

This is the structure for the kOS IF-THEN statement.

I'll add a few debug print statements to see where it fails.

EDIT:

Riiiiight, it's when it returns the variable "apospeed". The ORBITABLEVELOCITY class that it represents is not what I should be trying to do.

It should be "apospeed:velociyt:orbit", I think.

Edited by Starwhip
Link to comment
Share on other sites

So, apospeed looks like this:


ORBITABLEVELOCITY: ORBIT = V(X,Y,Z), SURFACE = V(X,Y,Z)

Where V(x,y,z) is a vector.

You can call "apospeed:orbit" to give you the orbit value.

How do you call the first value of the orbit vector? Vectors in the code are just tuples, but "apospeed:orbit[0]" fails.

EDIT:

"apospeed:orbit:X" is the correct syntax.

I'll see if that fixes it.

Edited by Starwhip
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...