Author Topic: A380 not recognized in py Script  (Read 694 times)

AUA9085

  • Full Member
  • ***
  • Posts: 124
    • My Youtube Profile :)
A380 not recognized in py Script
« on: November 01, 2024, 05:21:16 am »
Hey,

I am really not sure what I do wrong here, but the A380 entry wont be recognized, the AC always get reposition at the same position even if I change the value:
Code: [Select]
def customOffsetGatesMtH(aircraftData):
table = {
0: 11.00,
380: 10.50,
}

table787 = {
0: 11.50,
8: 11.50,
9: 11.50,
10: 11.50,
}

table777 = {
0: 11.00,
200: 11.00,
300: 11.00,
}

if aircraftData.idMajor == 777:
return Distance.fromMeters( table777.get(aircraftData.idMinor)  - 0.25 )
elif aircraftData.idMajor == 787:
return Distance.fromMeters( table787.get(aircraftData.idMinor)  - 0.25 )
else:
try:
return Distance.fromMeters( table.get(aircraftData.idMinor)  - 0.25 )
except:
return Distance()

Any idea why?

BR

SkyBoundSim

  • Newbie
  • *
  • Posts: 11
Re: A380 not recognized in py Script
« Reply #1 on: November 01, 2024, 10:15:55 pm »
It might be an indentation and logic error. Try this:

def customOffsetGatesMtH(aircraftData):
    table = {
        0: 11.00,
        380: 10.50,
    }

    table787 = {
        0: 11.50,
        8: 11.50,
        9: 11.50,
        10: 11.50,
    }

    table777 = {
        0: 11.00,
        200: 11.00,
        300: 11.00,
    }

    if aircraftData.idMajor == 777:
        return Distance.fromMeters(table777.get(aircraftData.idMinor, 11.00) - 0.25)
    elif aircraftData.idMajor == 787:
        return Distance.fromMeters(table787.get(aircraftData.idMinor, 11.50) - 0.25)
    elif aircraftData.idMajor == 380:  # Adding A380 recognition
        return Distance.fromMeters(table.get(aircraftData.idMajor, 10.50) - 0.25)
    else:
        try:
            return Distance.fromMeters(table.get(aircraftData.idMinor, 11.00) - 0.25)
        except:
            return Distance()  # Fallback if no match is found

virtuali

  • Administrator
  • Hero Member
  • *****
  • Posts: 51917
    • VIRTUALI Sagl
Re: A380 not recognized in py Script
« Reply #2 on: November 02, 2024, 12:59:33 pm »
I am really not sure what I do wrong here, but the A380 entry wont be recognized

Your logic is wrong, because your code only checks the airplane idMajor for 777 and 787, the "else" case is instead checking the idMinor only, which for the A380 would be 800.

AUA9085

  • Full Member
  • ***
  • Posts: 124
    • My Youtube Profile :)
Re: A380 not recognized in py Script
« Reply #3 on: November 02, 2024, 05:59:59 pm »
Hm, I am too stupid for it :D
Code: [Select]
def customOffsetGatesMtH(aircraftData):
    table = {
        0: 11.00,
800: 14.50,
    }

    table787 = {
        0: 11.50,
        8: 11.50,
        9: 11.50,
        10: 11.50,
    }

    table777 = {
        0: 11.00,
        200: 11.00,
        300: 11.00,
    }

    if aircraftData.idMajor == 777:
        return Distance.fromMeters(table777.get(aircraftData.idMinor) - 0.25)
    elif aircraftData.idMajor == 787:
        return Distance.fromMeters(table787.get(aircraftData.idMinor) - 0.25)
    else:
        try:
            return Distance.fromMeters(table.get(aircraftData.idMinor) - 0.25)
        except:
            return Distance()

Should that work? If yes, it did not :D
« Last Edit: November 02, 2024, 06:01:43 pm by AUA9085 »

virtuali

  • Administrator
  • Hero Member
  • *****
  • Posts: 51917
    • VIRTUALI Sagl
Re: A380 not recognized in py Script
« Reply #4 on: November 04, 2024, 12:39:52 am »
Quote
Should that work? If yes, it did not

Well, it should work in theory, although you used the worse possible approach since, for example, even a 737-800 or a 787-800 would also get the "A380" distance. A better solution was suggested by SkyBoundSim.

And you could have written the code way more compact:

Code: [Select]
def customOffsetGatesMtH(aircraftData):
    table = {
        777: 11.00,
        787: 11.50,
        380: 10.50,
    }

    return Distance.fromMeters(table.get(aircraftData.idMajor, 11.00) - 0.25)

Since all your 777s and all your 787s variants were all set to the same distance without any minor differentiation, no need to have a table for each plane, a single table for all major types would work, with a default value of 11.0 meters, to prevent errors in case the idMajor is not found in the table, which will act as default.
« Last Edit: November 04, 2024, 12:48:26 am by virtuali »