local Table = {
One = 5,
Two = One + 3
}
How would I reference One while defining Two? I tried doing
Two = self.One + 3
but it didn’t work.
Is this even possible? Because I need this to make what I want to make.
local Table = {
One = 5,
Two = One + 3
}
How would I reference One while defining Two? I tried doing
Two = self.One + 3
but it didn’t work.
Is this even possible? Because I need this to make what I want to make.
You would have to either manually define the key outside of the table or make a method and set the key from there.
What do you mean by this?
That you are asking is not possible at all. You should define your variables outside of the table and then add them to the table.
Ok, I found a workaround by defining each value individually
Table = {}
Table.One = 5
Table.Two = Table.One + 3
This might be what Omega or you said
Yep that’s one way to achieve what I mean.
I’m happy you found the solution .
Keep coding!
By the way if I helped you, please mark my answer as a solution in order to keep the rules in Roblox devforum.
local myTable = {
value1 = 10,
value2 = function()
local result = self.value1 + 5
return result
end
}
print(myTable.value2()) -- Output: 15
Yeah via method but that’s again after the table is defined. The function is called after that…