That does look like it should work. Can you explain more the purpose of this?
Also, use this module structure:
local module = {}
module.__index = module
function module.SomeNameHere()
end
return module
That does look like it should work. Can you explain more the purpose of this?
Also, use this module structure:
local module = {}
module.__index = module
function module.SomeNameHere()
end
return module
oh I am quite suprised I was able to accurately guess the layout of how module scripts would send requests.
I guessed this from my knowledge of how Roblox Lua usually does things.
The purpose of this is for my recording module which allows you to record things in roblox experiences and then play those recordings back.
I plan to use this module for things like running and creating video ads or replaying final kills/good moments in my games.
I am also planning on making this module public once its done.
local module = {}
function module:onChanged()
end
return module
you are forgetting the important part of how to fire it.
for example in mine I called
function module.onChanged(info)
return info
end
module.onChanged("Hello") -- fire recieving script
How would I fire the function for your version
You would have to fire through the script. (the server script not module)
Well, here’s a quick rundown:
--define the module
local myModule = {}
module.__index = myModule --set __index metamethod
--[[
Colon notation passes itself as an arguement
Dot notation does not
]]
--Init is a naming convention for subprograms that
--should only be run once as an initialisation
function myModule:Init(someInfo)
self.someInfo = someInfo
end
--now all your own subprograms can go below
--modules are especially useful in OOP because
--they can hold all the necessary items for a class
function myModule.NewClass()
local self = setmetatable({}, myModule) --this new table inherits everything from myModule
end
return myModule
I might have missed a few bits.
Here’s a post relating to dot and colon notation:
What is self and how can I use it? - Help and Feedback / Scripting Support - Developer Forum | Roblox
to clarify I want the module to be the one sending the info and the script recieving the info.
My module script will update a value, and when it updates the value, the script runs code with the new value, received from the module.
Some kind of RBXScriptSignal is going to be needed here. I’m not too sure on how you could make your own RBXScriptSignal, but I’m pretty sure there is a way.
Otherwise, you would need to use a while true
iterator to detect the change in variable and that would use a lot of memory .
isPaused
: Boolean variable controlled by a server script, determining if the playback is paused.isPaused
variable which is checked by the serverisPaused
to true.Why not use a value instance, like a BoolValue
? then, you could use .Changed
or :GetPropertyChangedSignal("Value")
to detect the change.
I see so rather than using a variable it would use a Bool object value.
This may work let me see…
now that I think about it rather than storing IsPaused on the server and the module script separately, I could set it on the module exclusively.
Then when I want the script to access it, I could use a getter method to determine the current value of IsPaused. That way when any changes are made on the module separately from the script accessing it, the script would save that state since it accesses the modules version not its own.
Yeah, but a value instance would probably be better, and might even take less memory.
Just adding to what is here already.
local module = {}
local x = 100 -- a script global value
function module.functionName()
local z = 200 -- a function global/only value
end
return module
And some documentation…
Intro to ModuleScripts
ModuleScript
Module script:
local module = {}
function module.functionName(newval)
return newval
end
while true do
task.wait(.1)
module.functionName("hello")
end
return module
local script:
local module = require(workspace.module)
module.functionName = function(newVal)
print(newVal)
end
So if I did this would it print “hello” ever .1 seconds on the local script?
Not quite…
Module:
local module = {}
module.__index = module
module.SomeValue = nil
function module:NameHere(newVal) --parameter "self" implicitely defined through notation
--return newVal - this makes the subprogram absolutely useless. Let's assign it to the module.
self.SomeValue = newVal
end
return module
LocalScript:
local module = require(path_to_module_here)
module:NameHere("Test value")
I am trying to get a bindable function behavior on the module.
for example remember the goal is that the local script prints hello every .1 seconds, which is fired by the module.
I suppose this is not possible but I saw datstore modules doing this
BindableFunction
behaviour might not be necessary - if you edit a variable that is within the module, it will update for anything that requires it. So, if I had this:
local module = {}
module.__index = module
module.someCoolVariable = "something"
return module
and then:
local module = require(--[[path to module here]])
print(module.someCoolVariable) --> "something"
this reminds me of java but I am not a fan of the
module.__index = module
I think that looks pretty weird. I feel like you should be able to do
module.someCoolVariable = "something"
without having to do that. Its also pretty hard to memorize writing module.__index = module
Yeah, it’s not entirely necessary, but it’s recommended. The __index
metamethod becomes more relevant in OOP.