This compiler allows you to define Simple Rockets 2 spacecraft flight programs using a Scala 3 DSL.
- Simple Rockets 2 installed
- Scala CLI installed
- Basic command line skills
Create a new file Hello.sc
with the following content:
//> using scala "3.1.1"
//> using lib "com.akmetiuk::simple-rockets-compiler:0.1.1"
import rocketscompiler.{ *, given }
program("Hello") {
displayText("Liftoff!")
activateStage()
Throttle := 1
}
Run scala-cli Hello.sc
. This will convert the script into the Simple Rockets 2 program and write it to the game.
Next, from the game, open whatever craft you want to execute the project on. Click the menu button at the top-left of the screen, click "Edit Program". From the program editor, click the menu button again, select "Load Program". Find the "Hello" program and load it.
Sometimes when you compile a script as described above, you may not find the program in Simple Rockets. Chances are the DSL failed at detecting the directory where Simple Rockets looks for programs correctly. If that is the case, you need to manually find out the location (e.g. described here). Then figure out where the game store the flight programs in that directory, by default should be UserData/FlightPrograms/
relative to the game directory.
Once you have the directory, you can explicitly specify it when writin a program as follows: program("Hello", java.io.File("/path/to/your/dir"))
The scripting language is still a work in progress, so not everything is ported yet from the game's built-in language. See the complete list of what's available here.
Following are some materials to organise the Scala in Science workshop:
- Presentation
- Blog Article on how to use it to get to orbit.
- Low Flyer Challenge Spacecraft
- Scala Setup on EPFL computers - this video details how you can set up the Scala environment on an EPFL computer.