From 6669becaff9c6462b09eb48c416a66754e82e6ba Mon Sep 17 00:00:00 2001 From: Jonathan Redpath Date: Sat, 9 Jun 2018 21:15:00 +0100 Subject: [PATCH] Switch to forindex() (thanks pinto) and messages cleared when vector is empty --- Nasal/ECAM-controller.nas | 27 +++++++++++++-------------- Nasal/ECAM.nas | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Nasal/ECAM-controller.nas b/Nasal/ECAM-controller.nas index 016147f1..62854e16 100644 --- a/Nasal/ECAM-controller.nas +++ b/Nasal/ECAM-controller.nas @@ -77,6 +77,8 @@ var messages_priority_3 = func { if (getprop("/controls/flight/flap-pos") > 2 and getprop("/position/gear-agl-ft") < 750 and getprop("/gear/gear[1]/position-norm") != 1 and getprop("/FMGC/status/phase") == 5) { msgs_priority_3.append("L/G GEAR NOT DOWN"); active_messages.append("L/G GEAR NOT DOWN"); + } else if (active_messages.contains("L/G GEAR NOT DOWN")) { + active_messages.remove("L/G GEAR NOT DOWN"); } } var messages_priority_2 = func {} @@ -86,6 +88,8 @@ var messages_memo = func { if (getprop("controls/flight/speedbrake-arm") == 1) { msgs_memo.append("GND SPLRS ARMED"); active_messages.append("GND SPLRS ARMED"); + } else if (active_messages.contains("GND SPLRS ARMED")) { + active_messages.remove("GND SPLRS ARMED"); } } @@ -111,24 +115,19 @@ var ECAM_controller = { messages_memo(); # write to ECAM - foreach(var ewd_messages; active_messages.vector) { - var i = 1; - var x = getprop("/ECAM/msg/line" ~ i); - print("Variable i is:" ~ i); - if (x == "") { - setprop("/ECAM/msg/line" ~ i, ewd_messages); + + forindex ( var i; active_messages.vector ) { + var line = 1; + if (getprop("/ECAM/msg/line" ~ line) == "") { + setprop("/ECAM/msg/line" ~ line, active_messages.vector[i]); } else { - i = i + 1; - setprop("/ECAM/msg/line" ~ i, ewd_messages); - print("Variable i is:" ~ i); + setprop("/ECAM/msg/line" ~ (line + 1), active_messages.vector[i]); } } - # debug - - foreach(var debug; active_messages.vector) { - print(debug); + if (active_messages.size() == 0) { + setprop("/ECAM/msg/line1", ""); + setprop("/ECAM/msg/line2", ""); } - }, }; diff --git a/Nasal/ECAM.nas b/Nasal/ECAM.nas index bbc7d84e..6a03b542 100644 --- a/Nasal/ECAM.nas +++ b/Nasal/ECAM.nas @@ -80,7 +80,7 @@ var ECAM = { setprop("/ECAM/ldg-memo-enable", 0); } - if (size(ecam.active_messages) > 0) { + if (ecam.active_messages.size() > 0) { setprop("/ECAM/left-msg", "MSG"); } else if (getprop("/FMGC/status/phase") == 0 and stateL == 3 and stateR == 3 and getprop("/ECAM/engine-start-time") + 120 < getprop("/sim/time/elapsed-sec") and getprop("/ECAM/to-memo-enable") == 1 and wow == 1) { setprop("/ECAM/left-msg", "TO-MEMO");