|
| 14 Dec 2015 11:10 AM |
| What's the idea behind the ModuleScript? A lot of people find it very useful, but I don't see a point of using it. It's basically a script where you run functions, that's all I know. Why is it so popular? |
|
|
| Report Abuse |
|
|
|
| 14 Dec 2015 11:11 AM |
| It is a really clean and modern way of organizing code. |
|
|
| Report Abuse |
|
|
| |
|
|
| 14 Dec 2015 11:13 AM |
| Can you explain a bit more? |
|
|
| Report Abuse |
|
|
V0ngola
|
  |
| Joined: 28 Aug 2012 |
| Total Posts: 508 |
|
|
| 14 Dec 2015 11:19 AM |
A ModuleScript is a Script-like object that contains code for a module. Unlike other scripts, a module does not execute when a game starts. The code in a module script can be run by calling the require global function with the ModuleScript as an argument. Its code is executed at the point it is required, and will only be executed once per peer (server/client). If a ModuleScript is required multiple times in the same environment the return value from the first execution will be used for every require call.
When writing code for a large project, you may find yourself defining the same function in several different places. Using module scripts, you can define a function in one place to be used in any number of scripts. This makes maintaining and updating code much easier, as you only have to make changes in one place (as opposed to searching for all the scripts where you use the function).
-http://wiki.roblox.com/index.php?title=API:Class/ModuleScript |
|
|
| Report Abuse |
|
|
|
| 14 Dec 2015 11:20 AM |
Well it is really clean and organized. You can use it in several ways to organize code. You can put code in it that can be used in multiple other scripts. You can make it a free model and the person using it can just use require(ModelId) so it doesn't make their place really messy. And so forth. |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 14 Dec 2015 11:27 AM |
| Modular code is very important in development. |
|
|
| Report Abuse |
|
|
| |
|
|
| 14 Dec 2015 11:28 AM |
| I'm making a Survival game, and I only use LocalScripts and ServerScripts and there are a lot of coding in it. Should I use ModuleScripts and would it make a very big difference? |
|
|
| Report Abuse |
|
|