generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Module running functions from the script it is called in

Previous Thread :: Next Thread 
Smeers is not online. Smeers
Joined: 14 Feb 2013
Total Posts: 797
20 Jul 2016 10:49 AM
Since I'm fairly new to modulescripts, I wanted to know how to run functions (and possibly events?) that are in the script the module was called from.

Would I return the functions in a table, like this?

--script
local tableofFunctions = {
Function1 = function(arg1,arg2) print('hi',arg1,arg2) end
-- Functions here
}
local module = require(script.Parent.Module)
module.FunctionName(tableofFunctions)

-- module
return {
FunctionName = function(tableofFunctions)
tableofFunctions.Function1(arg1,arg2)
end
}

--------

Or would I do something else?

any help is appreciated.
Report Abuse
Smeers is not online. Smeers
Joined: 14 Feb 2013
Total Posts: 797
20 Jul 2016 11:04 AM
Bumpers.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
20 Jul 2016 11:05 AM
I'd suggest giving it the environment of the calling script, but since multiple scripts could call it, things would become both confusing and buggy.
Report Abuse
Smeers is not online. Smeers
Joined: 14 Feb 2013
Total Posts: 797
20 Jul 2016 11:07 AM
I'm basically looking for a similar effect to Epix's plugin format.

Let me try that again:

--script
local tableofFunctions = {
Function1 = function(arg1,arg2) print('hi',arg1,arg2) end
-- Functions here
}
local module = require(script.Parent.Module)
module(tableofFunctions)

-- module
return function(tableofFunctions)
tableofFunctions.Function1(arg1,arg2)
end

---------------

or similar.
Report Abuse
Smeers is not online. Smeers
Joined: 14 Feb 2013
Total Posts: 797
20 Jul 2016 11:08 AM
In short, I want the module to have access to functions and events that the script that it is called from would run.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
20 Jul 2016 11:17 AM
How many different scripts will be requiring it?
Report Abuse
Smeers is not online. Smeers
Joined: 14 Feb 2013
Total Posts: 797
20 Jul 2016 11:26 AM
one.
Report Abuse
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
20 Jul 2016 11:47 AM
That's not what a modulescript is for
Report Abuse
Smeers is not online. Smeers
Joined: 14 Feb 2013
Total Posts: 797
20 Jul 2016 11:54 AM
Both, I've seen it done before, so I can preform the task that is obviously possible.
Report Abuse
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
20 Jul 2016 12:16 PM
http://wiki.roblox.com/index.php?title=Absolute_beginner%27s_guide_to_scripting
Come back in 5 years
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
20 Jul 2016 06:08 PM
Will you be requiring this at the top of your script, if so this is REALLY easy.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image