Howto:Create a new Nasal module
Jump to navigation
Jump to search
| Note Since $FG_ROOT is considered read-only, use $FG_ROOT/Nasal just for testing. |
This tutorial will document all the steps involved in creating a new Nasal module. Nasal is FlightGear's built-in scripting language.
- Create a new plain text file under
$FG_ROOT/Nasal/<module_name>.nas - Replace
<module_name>with the name for your new module (for exampletest) - Paste the following code into this file using a text editor:
# test.nas (save in $FG_ROOT/Nasal)
var mycode = func() {
print("My test module got loaded!");
};
setlistener("/sim/signals/nasal-dir-initialized", mycode);This piece of code defines a new function named mycode that just prints a message to the console (terminal/shell window).
| Note This code does not output anything to the FlightGear simulator screen, only the console window. |
Then you can use io.include("Nasal/test.nas"); to import the module.