Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How do I use methods in a module script?

Asked by
ausmel105 140
7 years ago

Hello,

I would like to find a way to get this method which is supposed to output a table with the raw string values of each airport name to work. Currently not even the method is being triggered/fired.

I would greatly appreciate any help.

My module script:

local airport = {}

airport.destinations = {
    Zakynthos = {
        Name = "Zakynthos";
        IATA = "ZAK"
    }
}

airport.airlines = {
    Airline = {
        Name = "Airline";
        GroupID = 1;
        IATA = "AA";
        Destinations = {
            airport.destinations.Zakynthos;
        }
    }
}

for i, v in ipairs(airport.airlines) do

    function v:GetDestinations()
        print("method fired")
        local dest = {}
        for _, x in ipairs(v.Destinations) do
            table.insert(dest, x.Name)
        end
        return dest
    end

end

return airport

Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local dest = airportData.airlines.Airline:GetDestinations()

for i, v in ipairs(dest) do
    print(v)
end

Thank you!

0
To get a module you must require. so just put local dest = require(airportData.airlines.Airline:GetDestinations). If I knew the answer to your other question, I would put this in an answer. (but i don't) DeveloperSolo 370 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Why do you have a GetDestinations method when you just re-iterate through them? Just iterate through airportData.airlines.Airline.Destinations. There's no point in having a method.

You're just over thinking it, bud.

Hope you can accept this as an answer.

Ad

Answer this question