Am I supposed to be storing the UserSettings object returned by calling UserSettings?

I’ve been seeing a lot of calls to UserSettings in the same script already provided (Animate, PlayerModule).
Is it just laziness or is there a certain reason for it?

And yes, I know what lazy instantiation is, but since they are called in quick succession, shouldn’t scoping it with a do end block be more optimal? So from

UserSettings():IsUserFeatureEnabled("UserCameraInputRefactor3")
UserSettings():IsUserFeatureEnabled("UserRemoveTheCameraApi")
UserSettings():IsUserFeatureEnabled("UserCameraToggle")
UserSettings():IsUserFeatureEnabled("UserCarCam")

To

do
   local UserSettings = UserSettings()
   UserSettings:IsUserFeatureEnabled("UserCameraInputRefactor3")
   UserSettings:IsUserFeatureEnabled("UserRemoveTheCameraApi")
   UserSettings:IsUserFeatureEnabled("UserCameraToggle")
   UserSettings:IsUserFeatureEnabled("UserCarCam")
end

I might have missed something, please let me know.

2 Likes

Actually putting a do end in a script is where you want your variable not to get exposed by outer space so i dont think it make a difference if you put do end or not

here is a thread where there is an explaining of do end How and when can I use the do - end?

1 Like

That’s beside the point., but I do want to point out the fact that it matters. Try running this script yourself.

--do
	local t = {}
	for i = 1, 1e5 do
		t[i]=true
	end
	
	print(gcinfo())
--end

wait()
print(gcinfo())

while true do
	print(gcinfo())
	wait()
end

After that, uncomment the do end block and you will surely see the difference

1 Like