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

Module scripts, operating like servers with requests, or repositories with pull/push?

Asked by 5 years ago

I just need to clarify whether module scripts act as a global script that functions can pass requests to, to be calculated, or if they act as scripts that can be 'downloaded' into other scripts to be run locally (essentially embedding).

I was under the impression that they operated similarly to remote events, however some recent code ive been running has been producing duplicate results, leading me to believe that they instead operate internally on the scripts that pull them, and overwrite variables when they are pushed back on completion.

Because of this, im currently using a rand func to assign time to before the functions are being run, so that their is no concurrent function being deployed that would either duplicate or overwrite the data of another in operation. Its not a very good fix, but for the moment it works, but I feel it would fail under a stresstest of multiple players.

If the code is copied out to each script pulling it, and it is infact a central process that is just being passed variables via request function, then il probably move to build a queue system to process each request individually, since theyre small and non time consuming. However if they are as theorised above, then im not sure what to do about my issue that would prevent these issues in an ironclad manor.

function module.Population(oldRegion, newRegion, Player)
    local x = math.random(10)/10
    wait(x + timeOffset)
    timeOffset = x
    if buildlock == true then       
        wait(1)
        module.Population(oldRegion, newRegion, Player)
    else
        --Actual code and other functions that I want to trigger

As you can see, im using a boolean statement to control majority of the requests, and an offset variable to manage any events triggered simultaneously. But for all I know, theyre both redundant pending on how these modulescripts actually operated.

Appreciate any solid explanation. Thanks

2 answers

Log in to vote
0
Answered by
ozzyDrive 670 Moderation Voter
5 years ago

A module is, by definition, "one of a set of separate parts that, when combined, form a complete whole." Modular programming relies on independent modules to build complex program-structures.

Roblox provides you with the ModuleScript object to write these independent code-files that can be required with Roblox's own require function. They are no different than any other lua files -- in fact, if you were developing with native lua, you'd have normal lua files work as your modules. A module is executed in the environment it's required in because the modules are there to extend the code running on that very machine.

They are absolutely not scripts running on the server but neither are they repositories. They are simply functions (one module can be thought of as a function (with a cached output) as it has to return a value to the requirer) separated into different files for organization purposes.

0
Is it possible to build a single script that handles the collisions for a subset of parts that are cloned into the workspace, rather than building a linked script and embedding it into each part that then runs the collision checks themselves? IcedMonopoly 2 — 5y
0
That's totally possible. You first need to get a reference to each part (by iterating over the table returned by Instance.GetChildren, for example), then simply connect the Touched event of each part to a function that handles the collision input. ozzyDrive 670 — 5y
0
So I would be looking at creating a table that stores the adresses for each required part to a table, and iterating over it with a do while loop on a global script to check for collisions? IcedMonopoly 2 — 5y
Ad
Log in to vote
0
Answered by
angeI1001 123
5 years ago

A module script acts like a localscript if it's being required from a localscript, and a regular script if required from a regular script.

Hope this helped you.

0
So it is instanced, and building a queueing system wouldnt work? IcedMonopoly 2 — 5y

Answer this question