rocketscompiler

Core Types

You can control the spacecraft by assigning variables of this type with the := operator.

You can control the spacecraft by assigning variables of this type with the := operator. For example, Thrust := 1 sets the engine to full power.

type Callback = Callback

A reaction to some event, such as the start of the game or a part exploding.

A reaction to some event, such as the start of the game or a part exploding.

type Expr = Expr

An expression, such as 2 + 2.

An expression, such as 2 + 2.

type SRProgram = BlockBuilder => Unit

A block of statements that will be written to the game as a program.

A block of statements that will be written to the game as a program. Primitive statements of this type, such as activateStage() to start the engine or assignment statements such as Thruottle := 1, are provided by this package. You can group them in blocks if you explicitly type those blocks as SRProgram. For example:

def helloWorld: SRProgram =
  displayText("Hello")
  waitSeconds(1)
  displayText("World")

Under the hood, SRProgram is a context function which takes the object that will remember all the expressions meant to be written to the game. If you omit the type, the compiler will complain that it can't find that object.

Entry Points

Where your program starts.

def callbacks(name: String, programFolder: File)(bs: Callback*): Unit

Use this entrypoint if you have more than one event you'd like to react to.

Use this entrypoint if you have more than one event you'd like to react to. This entrypoint can be useful e.g. if you want to start several programs in parallel at the start of the game. In this situation, you can use it as follows:

callbacks("Foo")(
  onStart { program1 },
  onStart { program2 }
}
Value parameters:
name

the name under which the program will be written to the game.

def program(name: String, programFolder: File)(p: SRProgram): Unit

The program defined by this entry point will be executed at the start of the game.

The program defined by this entry point will be executed at the start of the game. E.g.:

program("Foo") {
  displayText("Hello World")
}
Value parameters:
name

the name under which the program will be written to the game.

Autopilot

Triggers staging event.

Triggers staging event.

def lockHeading(hdg: String): SRProgram

Possible values for hdg are Retrograde or Prograde.

Possible values for hdg are Retrograde or Prograde. Retrograde means "back" and Prograde means "forward" (technically those directions are defined by the current velocity vector of the spacecraft).

Control

The program control flow structures specified here are exectued by the game during flight.

Immediately exit the loop where break() is called from.

Immediately exit the loop where break() is called from.

Display text on screen for the player to see.

Display text on screen for the player to see.

def forLoop(varName: String, from: Expr, to: Expr, by: Expr)(body: SRProgram): SRProgram

Custom variables are not implemented yet in this library, so for the time being there is no way to use varName from the forLoop, and the loop is thus equivalent to repeat.

Custom variables are not implemented yet in this library, so for the time being there is no way to use varName from the forLoop, and the loop is thus equivalent to repeat.

def ifElse(condition: Expr)(body: SRProgram)(elseBody: SRProgram): SRProgram
def ifTrue(condition: Expr)(body: SRProgram): SRProgram

Log without displaying to the player.

Log without displaying to the player. Logs can be viewed at the end of the flight.

def repeat(times: Expr)(body: SRProgram): SRProgram

Blocks the program until the expr Boolean condition is true.

Blocks the program until the expr Boolean condition is true.

def whileLoop(condition: Expr)(body: SRProgram): SRProgram

Inputs

Heading in degrees, 0 means North, 90 – East etc.

Heading in degrees, 0 means North, 90 – East etc.

Pitch in degrees, 90 means straight up.

Pitch in degrees, 90 means straight up.

Engine power, a Double from 0 to 1.

Engine power, a Double from 0 to 1.

Craft Information

object Altitude
object Fuel
object Orbit
object Velocity

Constants

val Prograde: String
val Retrograde: String

Givens

Givens

given given_Conversion_Boolean_Constant: Conversion[Boolean, Constant[Boolean]]
given given_Conversion_String_Constant: Conversion[String, Constant[String]]
given given_Conversion_T_Constant[T <: Double | Int]: Conversion[T, Constant[T]]

Extensions

Extensions

extension (x: AssignableCraftProperty)
def :=(y: Expr): SRProgram
extension (x: Expr)
def %(y: Expr): Expr
def &&(y: Expr): Expr
def *(y: Expr): Expr
def +(y: Expr): Expr
def -(y: Expr): Expr
def /(y: Expr): Expr
def <(y: Expr): Expr
def <=(y: Expr): Expr
def =!=(y: Expr): Expr
def ===(y: Expr): Expr
def >(y: Expr): Expr
def >=(y: Expr): Expr
def ^(y: Expr): Expr
def unary_!: Expr
def ||(y: Expr): Expr