local function Test(Test1 : Player, Test2 : Vector2)
end
But then again you have another way of doing it.
local function Test(Test1 : Player, Test2 : Vector2)
end
But then again you have another way of doing it.
Can’t confirm the autocomplete, haven’t tested this yet
If I were to try it, I would do something like this:
function Test():Decal
return Instance.new(“Part”)
end
And see if using the function returns a variable that has the Decal’s autofill (such as .Image) but actually returns a part.
Both methods is fine, but I guess function Do():ClassName is used if you aren’t using any arguments inside it.
Edit
*Can be used if you aren’t using any arguments.
That’s the return type, it states what type the function would give back. It basically makes it easier to use types since x would automatically be assigned the type Vector2:
function getPos():Vector2
local pos = workspace.CurrentCamera:WorldToScreenPoint(MS.Hit.Position)
return Vector2.new(pos.X,pos.Y)
end
local x = getPos() -- Autoassigned Vector2 type
It will return whatever you return though.
I knew it! Thanks for clarifying!
It was only because I tried finding documentation and found nothing
Yes, but the typechecking will assume it returns a Vector2 (since it’s the developer that says what type a function will return)
I see, if anything it makes it more readable, correct?
Which is nice
What if you were to return multiple types of variables? How would you do that with the syntax?
Can’t have multiple return types, you will have to do something like:
return {
1, 2, 3, 4, 5
}
That’s not true, you can do
return arg1, arg2, arg3
If you wanted multiple return types, you could use the “|” character:
function getPartOrModel(): BasePart|Model
local object = math.random(1,2) == 1 and Instance.new("Model") or Instance.new("Part")
return object
end
local x = getPartOrModel()
Yes you can do that too, but it’s more readable in a table for what I’m using it for
Even more interesting
hmmmmmmmmmmm
Thanks for this clarification, but what I meant originally was returning multiple variables, like this:
function foo()
return bar, wizz
end
I was talking about the function part, not the return keyword, but apparently you can just use |
Define it as a string then, since it will only return strings
Ah, I see. You can do this then:
function getPartAndModel(): (BasePart,Model)
return Instance.new("Part"),Instance.new("Model")
end
local x,y = getPartAndModel() -- x is assigned type BasePart, and y is assigned Model
If you need to return multiple values, use:
function foo(): (number, Vector2)
end