Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What is the best way to receive information from a ModuleScript more than once?

Asked by
Validark 1580 Snack Break Moderation Voter
8 years ago

Straightforward question.

ModuleScripts can only return values once to each client and once to the server.

What I have done in the past is send a location to the Module that it can put a StringValue or IntValue into. Then, I would tell the script to wait until a StringValue or IntValue appears:

repeat wait() until script:FindFirstChild("ValueWeAreWaitingFor") ~= nil;

Is there a better way? I notice Quenty's NevermoreEngine has a LoadCustomLibrary function in it. He says that Nevermore Engine caches ModuleScripts. All it seems to do is return a require() of the modules? (I may have just answered my question)

I am 50% sure this is what becomes the LoadCustomLibrary function in other scripts that use it:

local function LoadLibrary(LibraryName)
        --- Load's a modular script and packages it as a library. 
        -- @param LibraryName A string of the resource that ist the LibraryName

        -- print(Configuration.PrintHeader .. "Loading Library " .. LibraryName)

        local ModularScript = GetResource(LibraryName)

        if ModularScript then
            if ModularScript:IsA("ModuleScript") then
                -- print(Configuration.PrintHeader .. "Loading Library " .. ModularScript:GetFullName())
                local LibraryDefinition = require(ModularScript)

                --[[if type(LibraryDefinition) == "table" then
                    -- Import native definitions
                    for Name, Value in pairs(NativeImports) do
                        if LibraryDefinition[Name] == nil then
                            LibraryDefinition[Name] = Value
                        end
                    end
                --else
                    --error(Configuration.PrintHeader .. " Library '" .. LibraryName .. "' did not return a table, returned a '" .. type(LibraryDefinition) .. "' value, '" .. tostring(LibraryDefinition) .. "'")
                end--]]

                return LibraryDefinition
            else
                error(Configuration.PrintHeader .. " The resource " .. LibraryName 
                    .. " is not a ModularScript, as expected, it is a " 
                    .. ModularScript.ClassName, 2
                )
            end
        else
            error(Configuration.PrintHeader .. " Could not identify a library known as '" .. LibraryName .. "'", 2)
        end
    end

EDIT Specifically what I am looking for a more efficient way to do is: I am making a fun Cribbage game on Roblox, and I wrote a module to find the number of points in the hand. Here is the module, if you really want to see my code. Anyways, I have a localscript that is going to access the module like so:

local CribLib = require(game:GetService("ReplicatedStorage").CribLib)
--               ...  ...  ...  ..
local answers = script:WaitForChild("CardInstructions")
local keepCards = answers:WaitForChild("keepCards")
local tossCards = answers:WaitForChild("tossCards")
local keepCards = game.HttpService:JSONDecode(keepCards.Value)
local tossCards = game.HttpService:JSONDecode(tossCards.Value)
answers:Destroy()

I specifically, was wondering if there is a better method for receiving information from the Module.

0
Can you try to describe what you're trying to accomplish better? BlueTaslem 18071 — 8y
0
Edited it. Validark 1580 — 8y

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

I frankly don't understand your question.

ModuleScripts don't return only once, it's just that they only run they first time they are require'd and every time after they return the same thing they returned the first time, for example a Table or a Function.

You can require the same ModuleScript multiple times.

0
"You can require the same ModuleScript multiple times." was what I was looking for I guess. Thanks. Validark 1580 — 8y
Ad

Answer this question