Autocomplete Annotation Custom gone wrong

Greeting! I’m Haze, and I’m working on my UI module to make scripting much easier for me. Today I tried to add another functions in module and I noticed that my Annotation Custom (Child Module) didn’t work correctly.

Here’s the code:

Annotation
export type UIObject = {
	parent: GuiObject,

	-- Events
	Once: (self: UIObject, callback: () -> (), sound: string) -> UIObject,
	Click: (self: UIObject, callback: () -> (), sound: string) -> UIObject,
	Hover: (self: UIObject, callback: () -> (), sound: string) -> UIObject,
	UnHover: (self: UIObject, callback: () -> ()) -> UIObject,

	-- Effects
	Moveto: (self: UIObject, newPosition: UDim2, duration: number, style: string, direction: string, reverse: boolean, delay: number) -> UIObject,
	Resize: (self: UIObject, UIScale: number, duration: number, style: string, direction: string, reverse: boolean, delay: number) -> UIObject,
	Rotate: (self: UIObject, RotationValue: number, duration: number, style: string, direction: string, reverse: boolean, delay: number) -> UIObject,

	MovetoRandom: (self: UIObject, LimitArea: {minX: number, maxX: number, minY: number, maxY: number}, duration: number, style: string, direction: string, reverse: boolean, delay: number) -> UIObject,
	ResizeRandom: (self: UIObject, Range: {minVal: number, maxVal: number}, duration: number, style: string, direction: string, reverse: boolean, delay: number) -> UIObject,
	RotateRandom: (self: UIObject, Range: {minVal: number, maxVal: number}, duration: number, style: string, direction: string, reverse: boolean, delay: number) -> UIObject,
	
	MovetoAB: (self: UIObject, Location: {Start: UDim2, End: UDim2}, duration: number, style: string, direction: string, reverse: boolean, delay: number) -> UIObject,
	ResizeAB: (self: UIObject, Location: {Start: number, End: number}, duration: number, style: string, direction: string, reverse: boolean, delay: number) -> UIObject,
	RotateAB: (self: UIObject, Location: {Start: number, End: number}, duration: number, style: string, direction: string, reverse: boolean, delay: number) -> UIObject,
}

return {}

Main Problem:

So basically the annotation doesn’t match.

I would glad to hear your solution :ledger:
Thank you!

this is working as expected, the self argument is the first argument of every instance method where calling it with namecall : (colon) will automatically pass in the object as the self parameter.

since you type UI.new(...):MovetoAB() with a colon, the UI object gets passed as self, meaning there’s no need to pass it yourself which prevents redundant code

in order to see it better you can type .MovetoAB instead of :MovetoAB and you will see how the self argument is there again, because now you need to pass it yourself. using colon is better because you don’t have to put the instance each time, i.e.:

local instanceUi = UI.new(part);
- UI.MovetoAB(instanceUi, ...);
+ instanceUi:MovetoAB(...);

by the way, this is the completely wrong forum category, this is for forum bugs. please make sure your scripting support questions go in the scripting support category

1 Like

you should also mark an answer if your problem is solved so that the topic is solved as well.

it doesn’t solve the annotation problem, but I’ll note it.
Thank you!

Also, it seems like the annotation is completely fine. Sadly it isn’t match once I put something in an array.

i’m confused, the annotation problem was that it wasn’t the same, but it never will be because it is depending on how you call the function, wasn’t that the problem? you weren’t very descriptive with your issue and just said it didn’t “match”

yea my English is terrible ;-; I don’t know how to explain it in specific way.

If you watch the video I mentioned, you will see the module is:

but when I use some functions that has an array from the ‘()’, it wasn’t as same as I expected.

i just tested locally and it shows up in autocomplete

is this what you mean? because if so it is working fine

Yes, It’s working fine, but if the one who use module when they see this, they might input the value End first.

it’s not an array, it’s a table with any key values, you can not call it with [] anyway because it isn’t lua or luau syntax. i’m pretty sure many and all people would assume to input {End = etc, Start = etc}. the order does not matter in a table with keys like that because there isn’t any. it isn’t an array.

I admit that it’s a table not an array
As being said:

yes the function itself works completely okay, but I want to make it has a same position.
ex:

not { End: UDim2, Start: UDim2} to avoid misunderstanding

I think the cause may be from Lua itself.

i see now. your type’s order is Start then End, and the autocomplete’s order is End then Start.

because it is a table, the order of it does not matter.

local x = {a = 5, b = 6}

this is the same as

local x = {b = 6, a = 5}

which means when indexing it doesn’t matter the order the user puts them in, if that makes it easier for you to understand how little to nothing this change means.

but if you really are adamant and need to have the keys ordered, i don’t think it would be possible anyway without just making the rest of the code fit the unsorted keys which might change in the the future

That’s true

In my case, it’s another story..

function (bts)

--[[
	change the position from A to B
	@defaultValue: Location = {Udim2.fromScale(0,0), Udim2.fromScale(1,1)}
]]
function Effects:MovetoAB(Location: {Start: UDim2, End: UDim2}, duration: number, style: string, direction: string, reverse: boolean, delay : number)
	Location = Location or {UDim2.fromScale(0,0), UDim2.fromScale(1,1)}
	assert(Conditionals.isArray(Location,2,'UDim2') == true, 'Location is invalid')

	self.parent.Position = Location[1]

	duration, style, direction, reverse, delay = Conditionals.validateTweenArgs(duration, style, direction, reverse, delay)
	local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle[style], Enum.EasingDirection[direction], 0, reverse, delay)
	local tween = TS:Create(self.parent,tweenInfo,{Position = Location[2]})

	tween:Play()

	tweenInfo, tween = nil

	return self
end

as you can see, I can’t let

self.parent.Position = Location.Start

cuz it will give me an error in case I haven’t put anything when using this function

In other word, self.Parent.Position will equal to nil

I tried (including debug)

Function:

--[[
	change the position from A to B
	@defaultValue: Location = {Udim2.fromScale(0,0), Udim2.fromScale(1,1)}
]]
function Effects:MovetoAB(Location: {Start: UDim2, End: UDim2}, duration: number, style: string, direction: string, reverse: boolean, delay : number)
	Location = Location or {Start = UDim2.fromScale(0,0), End = UDim2.fromScale(1,1)}
	assert(Conditionals.isArray(Location,2,'UDim2') == true, 'Location is invalid')
	
	print(typeof(Location.Start))
    print(typeof(Location.End))
	
	self.parent.Position = Location.Start

	duration, style, direction, reverse, delay = Conditionals.validateTweenArgs(duration, style, direction, reverse, delay)
	local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle[style], Enum.EasingDirection[direction], 0, reverse, delay)
	local tween = TS:Create(self.parent,tweenInfo,{Position = Location.End})

	tween:Play()

	tweenInfo, tween = nil

	return self
end

Test1:

button:MovetoAB({UDim2.fromScale(0.2,0.2),UDim2.fromScale(0.9,-.05)},1.9)

the output showed me Location.Start and Location.End is nil

output:
Unable to assign property Position. UDim2 expected, got nil

Test2:

button:MovetoAB(nil,1.9)

this works as I expected

This is so hard :sob:

Plus, output give me info, Location contains this:

{
      [1] = {0.200000003, 0}, {0.200000003, 0},
      [2] = {0.899999976, 0}, {-0.0500000007, 0}
 }

hmmm.. That’s why Start and End is nil?

when calling it you’re meant to set those keys:

button:MovetoAB({
	Start = UDim2.fromScale(0.2,0.2),
	End = UDim2.fromScale(0.9,-.05)
}, 1.9)

since you’re indexing Location.Start, which is {Start = UDim2.fromScale(...), ...}, the key “Start” is set to the UDim2. by default, Luau will have numerical keys for the array-like tables: {"one", "two", "three"} is the same as {[1] = "one", [2] = "two", [3] = "three"}

i hope it makes sense that you need to either input the keys or switch over to actual array like tables, however it would make it confusing since you would need to know the order before hand and a table the order doesn’t matter so people just have to type Start and End which is better in my opinion.

your type annotation is literally for something like that, and not an array, i would recommend just using the string keys “Start” and “End”,

-but if using numerical keys (to make the table “array-like”) is really necessary then you need to update your type accordingly then it’ll match.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.