I am making a simulator with my friend Yes, I know simulators are getting annoying but it’s just easy to make and I wanted to see how it is to make an actual game - I am not gonna receive robux
I want to know how I should organize my Hierarchy, and which scripts I should use.
For example: What codeflow would I have for handling currency in the simulator? I thought about making a module script that will recieve input from a local script, handle currency and return a table that will have functions to show the currency.
But then, where will I store the input?
Also most people use really complex stuctures and modules and stuff - I want mine to be simple but efficient enough.
If anyone could give me tips that would be great, thanks!
Well first of all, what do you mean show the client a list of functions for the currency? Unless you have something weird with currency, this number can only go up or down.
Script hierarchy can also vary in effectiveness and method from programmer to programmer, but I’m going to give you how I’d do it.
I would keep a folder called “Modules” inside ServerScriptService, and add modules to, for example, purchase items, pets, and collectibles (call that ItemHandler). What I do for my game is make multiple “Handler” ModuleScripts, and then use those in just normal scripts which connect them to RemoteEvents/RemoteRunctions, and just execute necessary code.
I can’t really offer much more advice than that, just organize your code in modules (to avoid threading and coroutines) and do the rest the way you feel is most efficient.
Would you mind telling me how you think I should store the data? (In value objects? Inside variables of a specific script?)
Also, how would I make the modules work together? In order to execute certain functions in a module script, I would need data that comes from the script I’m requiring it from. Usually you would pass the variables as arguements, but that doesn’t seem like a good way of doing it with too much data and modules. Also I don’t think other people do it this way.
And how would those “handlers” work? I still don’t get it.
You store it in a table that a module returns? a table in a module but it doesn’t return it (returns something else)?
Something else inside the module?
Please explain.
Now you’re getting into the complications of ModuleScripts. My point is I use them to store data, and I modify them through the module functions. I just gave you how I organize scripts, not the intricacies of ModuleScripts.
The intricacies of ModuleScripts is a question probably aimed more for #help-and-feedback:scripting-support. I will say the way you get a value is this:
--Don't actually put modules in Workspace
local coolModule = require(workspace.VeryCoolModule)
--Example of getting data from a module
local tableOfChillPlayers = coolModule.ChillPlayers
print(tableOfChillPlayers[1] .. " is the chillest player"
In this case, assuming the module of chill players looked like this:
local module = {}
module.ChillPlayers = {"System502", "RedstonePlayz09"}
return module
Then the script we previously wrote would get the table of chill players, and then it would print out the following:
System502 is the chillest player
This is just the basics of getting data from a module script. If you want more detail, this would have to go into #help-and-feedback:scripting-support.
EDIT: Editing data in a module script is the same as reading it. Just do this:
local coolModule = require(workspace.CoolModule)
coolModule.ChillPlayers = {"System502", "RedstonePlayz09", "Enckripted"}
Also, I hadn’t quite understood your question correctly, due to I had replied to it pre-edit.
Sorry to be rude but you are obviously not reading my question. I asked how to edit the data, not access it.
I know about module scripts and I used them before.