Cassandra Posted February 23, 2013 Share Posted February 23, 2013 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. Link to comment
iPrestege Posted February 23, 2013 Share Posted February 23, 2013 I really do not know but you can use the files from any Script in your server (pictuers,sound,...) . Link to comment
Cassandra Posted February 23, 2013 Author Share Posted February 23, 2013 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. Link to comment
iPrestege Posted February 23, 2013 Share Posted February 23, 2013 No You Can't As What I Know' But You Can Use The Same "Event Name" As Far As I Know . Link to comment
Cassandra Posted February 23, 2013 Author Share Posted February 23, 2013 No You Can't As What I Know' But You Can Use The Same "Event Name" As Far As I Know . Yeah. I guess I have to stick with the "exports". Link to comment
iPrestege Posted February 23, 2013 Share Posted February 23, 2013 But believe me nothing is impossible (= . Link to comment
Fury Posted February 23, 2013 Share Posted February 23, 2013 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") Link to comment
Anderl Posted February 23, 2013 Share Posted February 23, 2013 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. Link to comment
Cassandra Posted February 23, 2013 Author Share Posted February 23, 2013 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. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now