my code have 2k+ lines and i want to shorten it
yeah i have problems with finding and editing codes since there 2k+ lines
im thinking of putting functions into modules an then load them
please give me any possible ideas to shorten the code
my code have 2k+ lines and i want to shorten it
yeah i have problems with finding and editing codes since there 2k+ lines
im thinking of putting functions into modules an then load them
please give me any possible ideas to shorten the code
i don’t know if shortening your code is the best idea to put into place here, i think organizing by putting them into functions that describe what it does in the name probably would be better. less code != better code
WAIT i just saw how many lines your script has
but it would still be better to have more functions with good names to prevent repeating code which would probably shorten it and make it more concise and self explanatory on what everything does
if things are used across multiple scripts then modules would be a good fit too
i actually add reusable functions, its just i put a lot of events in there
btw theres only one local script in my game
i dont like having a lot of scripts
that should be against roblox tos
ik please help dfigusdfkajhgjiofdvlkfjhgrjbifgrje
i would start from the top taking chunks of code that are common or complex and putting them into their own functions, in my opinion you shouldn’t have a module for one specific thing unless it’s a sort of system/utility/tool
ig that you are using that local script for handling most of the stuff
you can add multiple scripts rather than one like “GuiHandler” “CharacterHandler” “SmtHandler” etc…
also you can press CTRL+ F
to search for smt in the script
please use more whitespace omg
anyway,
split your code into module scripts, and use stuff like BindableEvents
(or simply do module.Function()
) to run the things you need to run at any time you want
this is… really bad, just saying
This should only be done when your running decompilers
Break it into modules and other local scripts
You’d probably benefit from a Single Script Architecture instead of keeping everything inside that one local script.
idk how does this work dfghjdmajvuigktjrksfjdv
Basically a Single Script Architecture is only having one Server Script and one Local Script, then through the local script you require what you need (Modules) an example would be like
--Client.lua (local script)
local HandleUserInput = require(script.UserInput)
HandleUserInput.ListenToEKey() -- This starts listening to the E Keycode
--UserInput.lua (Module Script)
local UserInputService = game:GetService("UserInputService")
function UserInput.ListenToEKey()
UserInputService.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.E then
print("E has been pressed")
end
end)
end
This is on the more intermediate side and a bare bones example, you could implement Object-Oriented Programming to further shorten it, but this will greatly reduce the amount of lines in your code.