Howto:Implementing a simple GCA system: Difference between revisions

Jump to navigation Jump to search
Line 110: Line 110:
<syntaxhighlight lang="nasal">
<syntaxhighlight lang="nasal">
var GCAController = {
var GCAController = {
# constructor
new: func(timer_interval_secs) {
new: func(timer_interval_secs) {
  var m = {parents:[GCAController] };
  var m = {parents:[GCAController] };
Line 121: Line 122:
  return m;
  return m;
}, # new()
}, # new()
# destructor
del: func() {
del: func() {
me.timer.stop();
me.timer.stop();
Line 126: Line 129:


#####
#####
# this will be called by our timer
update: func() {
update: func() {
print("Updating GCA controller");
print("Updating GCA controller");
Line 140: Line 144:
}, # update()
}, # update()


##### setup APIs:  
##### our setup APIs:  


setAircraft: func(root) {
setAircraft: func(root) {
me.root = root;
me.root = root;
# AI/MP models have their own callsign node:
# AI/MP models have their own callsign node:
var callsign_node = props.getNode(root);
var callsign_node = props.getNode(root).getNode("callsign");


# the main aircraft's callsign is stored under /sim/multiplay/callsign
# the main aircraft's callsign is stored under /sim/multiplay/callsign
if (callsign_node == nil) callsign_node = props.getNode("/sim/multiplay/callsign");
if (callsign_node == nil) {
print("Using multiplayer callsign");
callsign_node = props.getNode("/sim/multiplay/callsign");
}
else {
print("Using AI/MP callsign");
}


var callsign = props.getNode(callsign_node);
var callsign = callsign_node.getValue();
me.callsign = callsign;
me.callsign = callsign;
print("callsign: ", callsign);
print("callsign: ", callsign);
Line 172: Line 182:
append(me.receivers, receiver);
append(me.receivers, receiver);
}, #registerReceiver()
}, #registerReceiver()


notifyReceivers: func(instruction) {
notifyReceivers: func(instruction) {
Line 179: Line 190:
},
},


# start the GCA
start: func() {
start: func() {
  me.timer.start();
  me.timer.start();
}, # start()
}, # start()


# stop/interrupt the GCA
stop: func() {
stop: func() {
  me.timer.stop();
  me.timer.stop();
Line 214: Line 227:
buildInstruction: func() {
buildInstruction: func() {


return "Turn left";
return sprintf("%s Turn left",me.callsign);
}, # buildInstruction
}, # buildInstruction


}; # GCAController
}; # end of GCAController class


###
###
## test the class:  
## now, let's test our new class:  
###
###


Navigation menu