How do you personally organize/format your variables?

By variables, I mostly refer to that elongated declaration at the start of most of your core scripts. Have you gone through any measure to organize or paraphrase them, or do you simply declare them normally? Do you instantiate multiple variables in one line to minimize the amount of lines used in your code? Maybe you use a ModuleScript that contains some functions to shorten the hassle of declaring game service variables or a method that shortens the process of editing the properties of an object created with Instance.new(). You might even organize your variables by grouping relevant ones together in tables. What are your organizational principles and methods? Please share them!

well it completely depends on what the script is for. If it is an admin only thing I will most likely do

local admins = required(game.ServerStorage.Admins)

so that way i only have to change the table in that module script other wise it is mainly

local AdminOnlyDoor = script.Parent.Parent.AdminOnlyDoor

or

local AOD = script.Parent.Parent.AdminOnlyDoor
1 Like

I always do my variables in 3 chunks, with each one separated by two dashes

  1. Services
  2. Constants
  3. Code-exclusive variables (booleans, numbers, strings, etc.)

If there’s a particular constructor I know I’m going to use a ton, sometimes I might get lazy and create a variable specifically for the ‘new’ function of the constructor

local i_n = Instance.new
local v3 = Vector3.new
local ud2 = UDim2.new
1 Like

I frequently follow the Roblox Lua Style guide about the variables. Most variables are heavily descriptive to its usage and I usually avoid writing variables with one single character. Truncated variables are used when a pattern repeats, but that rarely occurs due to my usual modular programming paradigm.

In simple terms, variables are given camelCase, objects are given PascalCase and constants CONSTANT_CASE.

4 Likes

I had no clue such an in-depth guide existed and might begin practicing it for future projects. Thanks very much for sharing!