Make GUI X/Y Scale/Offset independently writeable

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)

4 Likes

would also like to be able to write directly to X/Y/Z vector components and CFrame components and Color3 rgb components.

4 Likes

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.

I first thought you meant that one UDim value is the same everywhere, but it isn’t:

local t = {} t[UDim2.new(1,2,3,4)] = 1 t[UDim2.new(1,2,3,4)] = 2 for k,v in pairs(t) do print(k,"=",v) end
--> {1, 2}, {3, 4} = 1
--> {1, 2}, {3, 4} = 2

You probably mean it’ll be like tables:

local udim = UDim2.new(1,2,3,4)
print(udim) --> {1,2}, {3, 4}
local function test()
	udim.X.Offset = 5
end
test()
print(udim) --> {1,5}, {3, 4}

A solution (for this “problem”) would be having methods like SetXOffset, that return an edited copy.

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.

That’s exactly what I meant, just reread the second code block of my post.

why shouldn’t it behave the same as just writing local function modify(x)x=x+Vector3.new(0,5,0)end?