Howto:Timers and properties
Jump to navigation
Jump to search
This article is a stub. You can help the wiki by expanding it. |
Objective
A timer that unpauses FlightGear 30 seconds after it starts, and then exits the simulator after a set number of seconds. It unpauses the simulator by setting these two properties:
/sim/freeze/master=0
/sim/freeze/clock=0
## $FG_HOME/Nasal/timedExit.nas
##
# the time for FG to run
var interval_sec = 30.00;
##
# afterwards, this timer will be triggered
var resume_sec = 20.00;
var unpause = func(){
print("unpause() called!");
var properties = [
{ name: "/sim/freeze/master", value: 0 },
{ name: "/sim/freeze/clock", value: 0 },
];
foreach(var prop; properties){
print("Setting '", prop.name, "' to ", prop.value);
setprop(prop.name, prop.value);
}
##
# start a new timer
print("Exit timer registered");
var exitTimer = maketimer(resume_sec, terminate_callback);
exitTimer.singleShot = 1;
exitTimer.start();
}
var terminate_callback = func(){
print("Terminating FG");
fgcommand("exit");
};
##
# http://wiki.flightgear.org/Nasal_library#maketimer.28.29_.282.11.2B.29
var myTimer = maketimer(interval_sec, unpause);
myTimer.singleShot = 1;
myTimer.start();
print("UnpauseTimer registered!");