local game = game
local exampleSomething = 5
local Enum = Enum
local UDim2 = UDim2
local A = Enum.KeyCode.A
local D = Enum.KeyCode.D
local W = Enum.KeyCode.W
local setmetatable = setmetatable
local print = print
local Vector2 = Vector2
local input = game:GetService"UserInputService"
local playerController = {}
playerController.__index = playerController
function playerController.new()
local self = {}
self.Walking = false
setmetatable(self,playerController)
return self
end
function playerController:Jump()
end
function playerController:Walk()
end
return playerController
The setup and class code look fine. The naming conventions are a bit counter-standard but that’ll end up mostly up to preference. You also don’t need to localize your globals either (local game = game
and co) as it won’t save any meaningful amount of time.
Wait so the self.Walking is alright?
And also I heard refrencing the variable before you use it is better
That was maybe true when Luau wasn’t around but in these days, Luau does that optimization for you so you don’t have to.
Are you sure, could you show me some proof; sorry I take performance very seriously
I have also read it, it can be found somewhere in one of the Luau threads, I do not remember where, I read it a while ago.
Localizing global variables like this will certainly have very negligible benefit, if any, it might even make it slower.
You take performance seriously, but localizing globals is certainly not the way to optimize, the real optimization is done within the logic of the code, only your time will be wasted in doing this redundant “optimization”.
Furthermore, you certainly should not try to optimize when you have no clear reason to do it.
What are these for? They’re literally just spam lines.
Ive seen someone in stack overflow do it and it was about something like global optimization i totally forget
But all you’re doing is re-defining the Roblox/Lua globals, there’s no reason to do that.
Hold on im gonna try to pull up the stackoverflow thread if I can find it
For this you can test it out yourself using os.clock() as a benchmarking tool as seen in the documentation for os and the example code given here. Usually you will get a time elapsed in the milliseconds or even lower region for this sort of optimization for 10000 iterations which shouldn’t be noticeable at all but try it out. I’ve already tried out some and found it to be insignificant
Otherwise, yeah that’s the classic OOP template setting your variables like that should be fine as that’s what I do for my OOP modules.
Finally someone who gets what Im trying to do, thanks man for clearing it up
bro, thats not optimization thats just slower, stop caring so much about literally 0.00000000000000001% of performance, which is probably WORSE using these methods.
yeah i know your right but i just cant not do it,
well your not right about the slower part I dont think dthecoolest did some test and said the results he got back were insignificant
That’s exactly what I’m trying to say lol; redefining globals is just wasting further resources.
just take it off like? why do you need Cframe = CFrame like??
That’s called laziness. What’s so hard about typing Vector3.new
?
Variables are meant for things that are larger, like sets of TweenInfo, or a player, etc.
-- Bad Practice:
local vec3 = Vector3.new
-- Good Practice:
local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
It’s not bad practice at all, assigning a global function to a variable can squeeze out some performance
-- Slower
for i = 1, 1000000 do
local x = math.sin(i)
end
-- Faster
local sin = math.sin
for i = 1, 1000000 do
local x = sin(i)
end
You’re talking about 0.0000000001% like @LucasTutoriaisSaimo said, which at the end of the day will you really care about?