Its super annoying when lets say I only want to adjust the offset position of a GUI to be based on its AbsoluteSize that I have to reconstruct the entire Position UDim2 when I’m only changing one value and it creates a long line of code to write it out to ensure the other values are preserved.
I should just able to do
GUI.Position.X.Offset = -GUI.AbsoluteSize.X/2
and safely assume all of the other values are preserved.
Instead of doing
GUI.Position = UDim2.new(GUI.Position.X.Scale,-GUI.AbsoluteSize.X/2,GUI.Position.Y.Scale,GUI.Position.Y.Offset)
Yeah this limitation is pretty painful (for all the types).
If this isnt possible, a method could be added (preferably all of the following, but it would be a lot of methods, not that it really matters):
udim:setXOffset(offset)
udim:setXScale(scale)
udim:setX(scale, offset)
udim:set(xs,xo,ys,yo) --doesnt save much writing so maybe not this one
udim:setScale(x,y) --or vector2
udim:setOffset(x,y) --or vector2
Additionally, arithmetic operations should be defined for all coordinate types (I dont think Color3 has those for example?).
TBH they shouldve just derived color3 from vector3 and UDim2 from a vector4 (if they really need to be their own types…)
I think your life would be much more painful if these types were mutable. They’re by-reference in Lua, so if you passed one to a function and it did any modification to it, it’d actually change yours. I’m not sure this is the behavior anyone really wants, so they’re immutable types.
No, that’s not what I was saying at all. I’m saying that you can’t change the encapsulated data of these types because they are passed around by reference:
local function modify(x)
x.Y = x.Y + 5 --pretend this works
end
local vector = Vector3.new(0, 0, 0) --> 0,0,0
modify(vector)
print(vector) --> 0,5,0
It’s not so far-fetched once you start trying to calculate things and shuffle data around.
Creating a copy is probably not too shabby of an idea, though.