How do I organize my code

This is what the explorer looks like minus startercharacterscripts (I don’t use starterplayerscripts I don’t really see a reason to?) I’m getting overwhelmed. Some of the code relates to eachother too and I’m starting to lose track of the relations.

How can I be more organized?

4 Likes

You could probably copy over the code from your local scripts and put them in a single local script (with comments to help distinguish which section does what whenever you need to revise the script).

This isn’t the best method as you’d have to constantly scroll through but I cant really think of any other method (my scripts are messy too).

Nah definitely not an option that would make the single local script thousands of lines long and a nightmare to maintain

2 Likes

I don’t really know how your scripts are formatted but you could combine modulescripts by just doing

local module = {}

module.QuestJournal = {

}

module.QuestRequirements = {

}

return module

Otherwise the solution could lay in becoming reliant on filter workspace/ctrl shift F to find script relationships easier.

I find that when beginning a new project it’s beneficial to plan out what you’re going to be adding and how to best organize that for your uses, opposed to just adding random scripts everywhere

2 Likes

Organize your Code by having a ModuleScript Contain Multiple ModuleScripts, so for Example, you have a Round System, you can have another ModuleScript inside like Events, or Map Data that would be used in the Round System.
If you have a DataStore system, Integrate the Modules together.

ModuleScripts are meant to help you Organize your Code, So Doing this would make it less Tedious to look for something and use it.

Something I like to do is to nest module scripts related to one another within each other. For example, for the quests I would create a module called Quests and parent both QuestJournal and QuestRequirements to it and require them from the Quests module. I would type the relevant code using the data and methods stored in the two child modules in the main Quests module.

Sometimes I create moduleScripts for specific functions alone such as the setup of a system… e.g. I have a moduleScript that handles pets, I would create a child moduleScript that creates/instances all the relevant folders, remotes, and values and call it Setup and require and call it from the main pets module. I would handle the remotes and values from using other modules, and might specify modules to handle whole events depending on how much code is involved.

1 Like

Ok I should have done that haha. That’s probably the standard way codebases are organized because i’m learning Angular at work and child components are related to the parent and (obviously) nested inside the parent. But it still overwhelms me :frowning: even when I nest related things together because there’s so many unrelated things or siblings.

Yeah the problem is that I don’t have a plan… I kind of just figure things out as I go and then do a rewrite at the end. I’m impatient.

You could create your own framework, where all server sided code and client side code have the same reference to stuff. Create a framework in a place only the server has access to with modules, and require them all at server start (You can decide on your own what modules should be loaded first). After the server have initialized all the code, copy the framework to Replicated Storage, so the client can initialize it afterwards. If there is some code you do not wish to be present on the client, just make sure that your server delete those modulescripts after initializing, but before copying to Replicated Storage.

For example if you have a pet hatching system, then there is no need for the client to know the exact percentage of drops, but a rounded number is enough. You can also hide drop chance completely of very rare pets this way.