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: When do you use a ModuleScript vs functions?

Previous Thread :: Next Thread 
ChiefTitan is not online. ChiefTitan
Joined: 03 Dec 2015
Total Posts: 2242
09 Jan 2016 05:06 AM
Either going to be using them too little or too much tbh.

Right now I have a DataManager script for example and it requires my SaveData and LoadData modules instead of just having them as functions.

What's your strategy ignoring the super easy examples?


Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
09 Jan 2016 05:10 AM
Is this a joke? I think you meant _G lmao
Report Abuse
Silvestris is not online. Silvestris
Joined: 02 Mar 2013
Total Posts: 111
09 Jan 2016 05:14 AM
"SaveData and LoadData modules"

i don't see why you'd split these into different modules (unless they both were pretty big or different purposes)
if anything I'd say DataManager is a module with these two sets of functions inside
Report Abuse
ChiefTitan is not online. ChiefTitan
Joined: 03 Dec 2015
Total Posts: 2242
09 Jan 2016 05:16 AM
"i don't see why you'd split these into different modules (unless they both were pretty big or different purposes)"

DataManager just has the PlayerAdded, PlayerRemoving functions and the game.OnClose callback, SaveData has packData and another function or two IIRC. LoadData has unpackData and clonePlayerTemplate and a bunch of other functions.

@cnt

No I mean what I meant. When would you have something in a whole modulescript as opposed to just having it as a function, I find modulescripts make everything way cleaner.


Report Abuse
direMitten is not online. direMitten
Joined: 18 Jun 2015
Total Posts: 1294
09 Jan 2016 05:49 AM
You can't really have too many ModuleScripts, unless you're *trying* to make it harder for yourself. Using ModuleScripts to make your scripts cleaner is a good idea. How little you want each module to be is up to you. But like some others suggested, having two separate modules for loading and saving seems a bit over the top.

In the end, you're probably the only one who's going to be reading your code. Just do what you want.
Report Abuse
ByDefault is not online. ByDefault
Joined: 25 Jul 2014
Total Posts: 3197
09 Jan 2016 05:51 AM
I'd suggest formatting your modules like this

fun = {}

function fun:LoadData(player,data)

end

return fun

It looks a lot cleaner, and makes it so you don't need a separate module for each function
Report Abuse
icanxlr8 is not online. icanxlr8
Joined: 25 Feb 2009
Total Posts: 3686
09 Jan 2016 06:55 AM
I just ditch modulescripts entirely. I use BindableEvents and stuff like that when I need to do the same stuff from different scripts.

Rock on! http://www.roblox.com/games/121584089/Rock-Roleplay
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
09 Jan 2016 07:02 AM
"I just ditch modulescripts entirely. I use BindableEvents and stuff like that when I need to do the same stuff from different scripts."

ModuleScripts and BindableEvents are completely different things.


Report Abuse
icanxlr8 is not online. icanxlr8
Joined: 25 Feb 2009
Total Posts: 3686
09 Jan 2016 07:04 AM
I find their functions to be the same. You can set a function inside of a ModuleScript, you can set a function inside a BindableEvent. Not much of a difference.

Rock on! http://www.roblox.com/games/121584089/Rock-Roleplay
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
09 Jan 2016 07:08 AM
"I find their functions to be the same. You can set a function inside of a ModuleScript, you can set a function inside a BindableEvent. Not much of a difference."

What? No.

ModuleScripts for for storing code that will run once when first required then returns the same value to every require afterwards.

BindableEvents are for sending values possibly between scripts.


Report Abuse
gskw is not online. gskw
Joined: 05 Jan 2013
Total Posts: 1364
09 Jan 2016 07:17 AM
And BindableEvents run asynchronously.

Also, if I were to do a DataManager script, I would put both SaveData and LoadData functions in the same module.
Report Abuse
icanxlr8 is not online. icanxlr8
Joined: 25 Feb 2009
Total Posts: 3686
09 Jan 2016 07:31 AM
Not necessarily. I've used BindableEvents to fire a Broadcast function to broadcast a message to the server when fired. I've just never seen a use for ModuleScripts that I can't replicate with BindableEvents and the like.

Rock on! http://www.roblox.com/games/121584089/Rock-Roleplay
Report Abuse
Happywalker is not online. Happywalker
Joined: 05 Mar 2010
Total Posts: 3672
09 Jan 2016 07:50 AM
Tfw when the "chief of this forum with a lot more place visits than us" doesn't know this
Report Abuse
ChiefTitan is not online. ChiefTitan
Joined: 03 Dec 2015
Total Posts: 2242
09 Jan 2016 07:57 AM
"Tfw when the "chief of this forum with a lot more place visits than us" doesn't know this"

It's a stylistic choice you can make so stop being so jealous and salty


Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
09 Jan 2016 08:10 AM
"I've just never seen a use for ModuleScripts that I can't replicate with BindableEvents and the like."

Ok.

1. Run some code.
2. Distribute code and values through asset id alone.
3. Efficiently distribute values(utility functions and such) to multiple scripts on the same machine.

BindableEvents simply cannot do what ModuleScripts do, what don't you understand, they literally do completely different things.


Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
09 Jan 2016 08:33 AM
Do this with a bindable :P

-Make a table
-Allow multiple scripts to modify this table
-Make sure all scripts see this change



So basically recreate _G with a bindable.
Report Abuse
Happywalker is not online. Happywalker
Joined: 05 Mar 2010
Total Posts: 3672
09 Jan 2016 02:30 PM
It can be a stylish difference but in some cases they really provide other needed functionality
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
09 Jan 2016 03:43 PM
OP you do realize that a ModuleScript is only run once, right? The results are cached, meaning what you want to do will only be done once. You don't use ModuleScripts as a replacement for "functions", you use functions.

The whole purpose of ModuleScripts is so you can easily reuse code without much overhead./
Report Abuse
ChiefTitan is not online. ChiefTitan
Joined: 03 Dec 2015
Total Posts: 2242
09 Jan 2016 04:08 PM
Yes I know that but I mean when do you just declare the function in the main script versus use an actual ModuleScript specifically


Report Abuse
sycips is not online. sycips
Joined: 21 Mar 2011
Total Posts: 1368
09 Jan 2016 04:18 PM
@ChiefTitan
I gotta admit, that's a good question. Personally I think that putting all functions in the main script is the most efficient, since it would probably takes more time to import a ModuleScript than to declare a function in a script. But on the other hand, I've made scripts with 15 functions or something inside one script and I gotta admit, it'll finally be very hard to code, because you're spending half of your time searching for code or the right spot to code xD
If I have to give you advise, put functions with the same subject in the same modulescript. Like 1 ModuleScript for creating triangleterrain, one modulescript for handling GUI animations on a dancefloor or one modulescript for handling cameramovement calculations. The mainscript should just be about controlling all the modulescripts. Think of it as an AdminGui maybe. The commands should be the modulescripts and the calling of the commands should be done by the main script!

I hope I cleared up your mind a bit... Good luck scripting! :D

~sycips~
Report Abuse
ChiefTitan is not online. ChiefTitan
Joined: 03 Dec 2015
Total Posts: 2242
09 Jan 2016 04:33 PM
Yeah sycips that probably sounds the best


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