20,741
edits
No edit summary |
|||
| Line 13: | Line 13: | ||
var interval_sec = 1.00; # sync properties at an interval of 1 sec | var interval_sec = 1.00; # sync properties at an interval of 1 sec | ||
var run_sync = func() settimer(sync, interval_sec); | var run_sync = func() settimer(sync, interval_sec); | ||
var clamp = func(min,max) { | |||
return func(x) { | |||
if (x < min) return min; | |||
if (x > max) return max; | |||
return x; | |||
} | |||
} | |||
# list of properties that you want sync'ed (source => target) | # list of properties that you want sync'ed (source => target) | ||
var properties = [ | var properties = [ | ||
{ source: "/velocities/airspeed-kt", target: "/mossie/airspeed-kt" }, | { source: "/velocities/airspeed-kt", target: "/mossie/airspeed-kt", process: clamp(min:10,max:50) }, | ||
{ source:"/velocities/airspeed-kt", target: "/hoorays/airspeed-kt" }, | { source:"/velocities/airspeed-kt", target: "/hoorays/airspeed-kt", process: clamp(min:0 ,max:100) }, | ||
# add more lines/properties as needed here (copy/paste and customize) | # add more lines/properties as needed here (copy/paste and customize) | ||
| Line 30: | Line 38: | ||
var sync = func { | var sync = func { | ||
if (debug_on) print("Syncing properties:"); | if (debug_on) print("Syncing properties:"); | ||
foreach(var property; properties) { | foreach(var property; properties) { | ||
var target_prop = property.target; | var target_prop = property.target; | ||
var source_value = getprop(property.source); | var source_value = getprop(property.source); | ||
if (debug_on) print(" Syncing: ", property.source, "(",source_value,") =>", target_prop); | var processed_value = property.process!=nil and property.process(source_value); | ||
if (debug_on) print(" Syncing: ", property.source, "(",source_value,") =>", target_prop, " Processed:", processed_value); | |||
setprop( target_prop, source_value ); | setprop( target_prop, source_value ); | ||
} | } | ||
run_sync(); | run_sync(); | ||
} | } | ||
| Line 46: | Line 55: | ||
_setlistener("/sim/signals/fdm-initialized", run_sync); | _setlistener("/sim/signals/fdm-initialized", run_sync); | ||
if (debug_on) print("sync.nas loaded"); | if (debug_on) print("sync.nas loaded"); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Nasal howto]] | [[Category:Nasal howto]] | ||