Jump to content

A way to reuse a function on other files


Cassandra

Recommended Posts

Posted

Is there a way to reuse a function on different files?(Doesn't matter if it's server/client) For example if I have this code in s_player.lua

  
function multi_check( source, ... ) 
    local arguments = { ... }; 
  
    for _, argument in ipairs( arguments ) do 
        if argument == source then 
            return true; 
        end 
    end 
    return false; 
end 
  

I want to use that function on all of the different files.

Posted
I really do not know :? but you can use the files from any Script in your server (pictuers,sound,...) .

Ooops sorry for not explaining better. I'm needing a method to use a function from other files on the same resource. So, for example I want to use that function above to my other scripts on the same resource. I don't want it to declare over and over again for each scripts.

Posted

add this code to your meta.xml;

<export function="multi_check" type="server" /> 
-- or 
<export function="multi_check" type="client" /> 

usage;

exports.resource_name:function_name(arguments) 
-- so your resource name is "amk" then 
exports.amk:multi_check(source,"bla bla") 

Posted

NO, simply no. You export a function to use it in multiple resources. A function created in a server file, as long as not declared as a local variable, can be called from other server side files in the same resource. What you can do is create a file that stores all common functions (I mean, that has function that can both be declared in server and client side, just like that function you posted). Then, add the file to the meta as client and server.

Posted
NO, simply no. You export a function to use it in multiple resources. A function created in a server file, as long as not declared as a local variable, can be called from other server side files in the same resource. What you can do is create a file that stores all common functions (I mean, that has function that can both be declared in server and client side, just like that function you posted). Then, add the file to the meta as client and server.

I will try that. Thanks for the tips.

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...