diff --git a/Nasal/FMGC/flightplan.nas b/Nasal/FMGC/flightplan.nas index 4a584789..b5672f44 100644 --- a/Nasal/FMGC/flightplan.nas +++ b/Nasal/FMGC/flightplan.nas @@ -222,14 +222,24 @@ var flightPlanController = { if (force) { me.flightplans[plan].insertWP(createDiscontinuity(), index); } - if (index > 0) { - if (me.flightplans[plan].getWP(index).wp_name != "DISCONTINUITY" and me.flightplans[plan].getWP(index - 1).wp_name != "DISCONTINUITY") { - me.flightplans[plan].insertWP(createDiscontinuity(), index); - } - } else { - if (me.flightplans[plan].getWP(index).wp_name != "DISCONTINUITY") { + + if (me.flightplans[plan].getWP(index) != nil) { # index is not nil + if (me.flightplans[plan].getWP(index - 1) != nil) { # index -1 is also not nil + if (me.flightplans[plan].getWP(index).wp_name != "DISCONTINUITY" and me.flightplans[plan].getWP(index - 1).wp_name != "DISCONTINUITY") { + me.flightplans[plan].insertWP(createDiscontinuity(), index); + } + } else { # -1 is nil + if (me.flightplans[plan].getWP(index).wp_name != "DISCONTINUITY") { + me.flightplans[plan].insertWP(createDiscontinuity(), index); + } + } + } elsif (me.flightplans[plan].getWP(index - 1) != nil) { # index is nil, -1 is not + if (me.flightplans[plan].getWP(index - 1).wp_name != "DISCONTINUITY") { me.flightplans[plan].insertWP(createDiscontinuity(), index); } + } else { # both are nil?? + print("Possible error in discontinuities!"); + me.flightplans[plan].insertWP(createDiscontinuity(), index); } }, diff --git a/Nasal/MCDU/ARRIVAL.nas b/Nasal/MCDU/ARRIVAL.nas index f06d8bb7..807c6daf 100644 --- a/Nasal/MCDU/ARRIVAL.nas +++ b/Nasal/MCDU/ARRIVAL.nas @@ -711,9 +711,9 @@ var arrivalPage = { me.updatePage(); } elsif (index == 6 and me.activePage != 2) { if (fmgc.flightPlanController.temporaryFlag[me.computer]) { - setprop("/MCDU[" ~ i ~ "]/page", "F-PLNA"); + setprop("/MCDU[" ~ me.computer ~ "]/page", "F-PLNA"); } else { - setprop("/MCDU[" ~ i ~ "]/page", "LATREV"); + setprop("/MCDU[" ~ me.computer ~ "]/page", "LATREV"); } } elsif (me.activePage == 0 and index != 6) { if (size(me.approaches) >= (index - 2) and index != 2) { # index = 3, size = 1