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 scripts

Previous Thread :: Next Thread 
AlexTheCreator is not online. AlexTheCreator
Joined: 10 Jun 2012
Total Posts: 144
17 Aug 2017 10:35 AM
just a few questions about mod scripts, just starting with them and the wiki is a little confusing.. If you could help me out that'd be great :)

local MyModule = {} -- What do I do with this bracket?

local light = script.Parent --does this have to be within the function?

function lighting()
if light.Name == "day_light"
then return light.Enabled = true --is this how you're supposed to use return?
elseif light.Name == "night_light"
then return light.Enabled = false --is this how you're supposed to use return?
end
end


script within the part:
require(workspace.MyModule, lighting) --will this call the function from the module?

also do i have to put a while loop so it will keep checking the module script?

Thanks guys!
Report Abuse
Flubberlutsch is not online. Flubberlutsch
Joined: 27 Sep 2016
Total Posts: 188
17 Aug 2017 10:36 AM
http://wiki.roblox.com/index.php?title=API:Class/ModuleScript
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
17 Aug 2017 10:38 AM
I'm gonna go with a big no to all your questions.

You should stay away from modules for now.
Report Abuse
AlexTheCreator is not online. AlexTheCreator
Joined: 10 Jun 2012
Total Posts: 144
17 Aug 2017 10:40 AM
lmao oki doki i'll read ######## ## all again and see if anything clicks :P Thanks anyway!
Report Abuse
Ajastra is not online. Ajastra
Joined: 01 Aug 2017
Total Posts: 1461
17 Aug 2017 10:41 AM
Hi Alex. You should learn about tables. The curly brackets form a "table constructor" expression.

Usually modules return tables of functions that can be called on by the code requiring it.

"return light.Enabled = true"

This is invalid syntax. The singular equals sign is the assignment operator, we use two equals signs to test for equality.

Return is also used to return a value to a caller function. If you just want to set a property, remove the "return" and just set light.Enabled = false, or light.Enabled = true.

The lighting() function is not called anywhere. Also, it's very weird to put a ModuleScript inside a light.





Report Abuse
JDLENL is online. JDLENL
Joined: 23 Dec 2009
Total Posts: 1109
17 Aug 2017 10:42 AM
local MyModule = {}

{} marks a table, which is what the module returns.

you HAVE to put a return MyModule in the modulescript or it won't function.

as well, you have to define lighting() as part of the module table, like this:

function MyModule:lighting(args)
--your stuff
end

then just end the module with that return MyModule statement

in the part, require only takes one argument: the module.

require(workspace.MyModule):lighting(args)

no idea why you'd want a while loop
Report Abuse
Ajastra is not online. Ajastra
Joined: 01 Aug 2017
Total Posts: 1461
17 Aug 2017 10:44 AM
Oh, and by the way, a module must return exactly one value.

Code in the module will be executed one time for whatever computer the code runs on. Every time you require() that same module after that, it will return the same value.


Report Abuse
JDLENL is online. JDLENL
Joined: 23 Dec 2009
Total Posts: 1109
17 Aug 2017 10:46 AM
^correct.

so if you wanted to use the functions in a module multiple times, do:

local module = require(workspace.MyModule)

while wait(60) do
module:lighting(args)
end

"module" will then store what MyModule returns, and if that is a table full of functions, you have a library that you can reference as "module" in the script.

is that what you meant by a while loop?
Report Abuse
AlexTheCreator is not online. AlexTheCreator
Joined: 10 Jun 2012
Total Posts: 144
17 Aug 2017 10:59 AM
right cool, some of the issues were just because I was tping it straight into the forum like not putting local before the function, totally would've noticed that if it was in blue :P

I won't be putting the module inside a light I'll be putting it in script storage and calling it from different scripts that are inside lights.. Just thought It'd let me change things more easily and stuff?

yeah thats pretty much what i meant by a while loop, just because i wanted the module to run more than once..


All of these explanations were really useful, especially "return", I should be able to figure out any other issues from what you've given me.

Thank you so much for taking the time to reply :D
Report Abuse
CMcHuggh is not online. CMcHuggh
Joined: 02 Jun 2017
Total Posts: 14
17 Aug 2017 11:02 AM
Lol
Report Abuse
CMcHuggh is not online. CMcHuggh
Joined: 02 Jun 2017
Total Posts: 14
17 Aug 2017 11:06 AM
just a few questions about mod scripts, just starting with them and the wiki is a little confusing.. If you could help me out that'd be great :)

local MyModule = {} -- What do I do with this bracket?

local light = script.Parent --does this have to be within the function?

function lighting()
if light.Name == "day_light"
then return light.Enabled = true --is this how you're supposed to use return?
elseif light.Name == "night_light"
then return light.Enabled = false --is this how you're supposed to use return?
end
end


script within the part:
require(workspace.MyModule, lighting) --will this call the function from the module?

also do i have to put a while loop so it will keep checking the module script?

Thanks guys!
Report Abuse
AlexTheCreator is not online. AlexTheCreator
Joined: 10 Jun 2012
Total Posts: 144
17 Aug 2017 11:07 AM
lol guy trying to learn how to do something to become better at it,
lol wouldn't ever be caught asking about something I don't understand glad I knew everything as soon as I was born.


??
Just leave, why bother? It's baffling.
Report Abuse
CMcHuggh is not online. CMcHuggh
Joined: 02 Jun 2017
Total Posts: 14
17 Aug 2017 11:08 AM
right cool, some of the issues were just because I was typing it straight into the forum like not putting local before the function, totally would've noticed that if it was in blue :P

I won't be putting the module inside a light I'll be putting it in script storage and calling it from different scripts that are inside lights.. Just thought It'd let me change things more easily and stuff?

yeah thats pretty much what i meant by a while loop, just because i wanted the module to run more than once..


All of these explanations were really useful, especially "return", I should be able to figure out any other issues from what you've given me.

Thank you so much for taking the time to reply :D
Report Abuse
AlexTheCreator is not online. AlexTheCreator
Joined: 10 Jun 2012
Total Posts: 144
17 Aug 2017 11:20 AM
great meme Connor, loved every second of it
Report Abuse
AlexTheCreator is not online. AlexTheCreator
Joined: 10 Jun 2012
Total Posts: 144
17 Aug 2017 11:25 AM
Connor, your place is ridden with virus and free models.
This is a forum for people to share ideas and get better at things they struggle with, please leave as it is evident that you have nothing to contribute.
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