How to implement these variables in the cleanest way?

This is a passage of my 300 line long code (I’m trying to reduce it):

local button1 = DialogueGui.Frame.Frame["1"]
local button2 = DialogueGui.Frame.Frame["2"]
local button3 = DialogueGui.Frame.Frame["3"]

Is there a better (shortest) way to implement these variables?

I know that I can do it like that:
local button1, button2, button3 = DialogueGui.Frame.Frame["1"], DialogueGui.Frame.Frame["2"], DialogueGui.Frame.Frame["3"]

But it’s the same thing just pressed into one line (122 characters)

1 Like


local frame = DialogGui.Frame.Frame

locan button1 = frame["1"]

And repeat this for each one

1 Like
local Frame = DialogueGui.Frame.Frame
local Buttons = {Frame[1],Frame[2],Frame[3]}

could do it like this
then button1 is
Buttons[1] etc


But this is easier and shortest

1 Like

Your code is an improvement over OP, but @S0MBRX’s code shortens it even more.

Your code would be:

local frame = DialogGui.Frame.Frame

local button1 = frame["1"]
local button2 = frame["2"]
local button3 = frame["3"]

--Test (this one doesn't need brackets):

Whereas their code is much shorter:

local Frame = DialogueGui.Frame.Frame
local Buttons = {Frame["1"],Frame["2"],Frame["3"]}

--Test (you just add [] around the number this time)

They both function the same, it’s just his is more clean, if you will.

1 Like