Jump to content

Exporting OOP functions that use existing player class


Noki

Recommended Posts

function Player:test() 
    outputDebugString(self:getName()) 
end 

How would I go about exporting something like this? There is another thread that mentions using loadstring, but that really only works if I want to import the class. However, since I'm using the existing player class (containing a table with all the player functions) how would I go about running this function from another resource?

Link to comment

Example:

function Player:getName() 
    return self.name 
end 
  
function execute(fc,p) 
    for k, v in pairs(Player) do 
        if k == fc then 
            return v(p) 
        end 
    end 
end 

local playerName = exports.playerClass:execute("getName",thePlayer) 
outputDebugString(playerName) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...