Trying to understand parameters

Hey guys, I’ve been trying to understand why some codes have things like these.

local function Color3ParameterTest(Color: Color3, Name: string)

Can somebody try explaining to me in a simple way since I’m half way to intermediate

1 Like

They just specify what class/type the parameter should be, just helps with understanding the code, and sometimes helps the type solver autocomplete methods and constructors in OOP programming.

These are also not limited to parameters:

local Part : BasePart = workspace.Part

They are not necessary though.

1 Like

That isn’t needed the before : is adding the type.

1 Like

I thought it was something done for style in their code

This is to express the type more clearly and to make it easier to use. Unlike other programming languages, there will be no error when the parameter you enter does not conform to the type.

1 Like

Well… style is probably the wrong word, I think you mean readability…

Again, its not necessary, its only used to specify the type.

1 Like

Ohhhhh, that’s why. I understand most of it

basically:

function OnChildAdded(child: Instance)
-- .ChildAdded automatically passes the instance that was added as a parameter
-- but if you remove the : Instance, the type solver will treat the parameter as 'any'

-- meaning auto complete won't be a thing, and you'll have to type it out manually
-- for example:
--[[
with : -> child.CF -> type solver will allow you to auto complete it by showing a list, in this case it will show you cframe
without : ->  child.CF -> type solver will not do anything, you'll have to type out CFrame manually

anything after the CFrame will autocomplete if you define the type, but won't if you don't
basically, it just makes life easier and also makes your code more readable and understandable

this is the simplest it can get really, this is really helpful if you're doing stuff like fetching values from module scripts, etc.
]]
end

workspace.ChildAdded:Connect(OnChildAdded)
3 Likes

ye, that’s what I mean. Thanks for the correction

1 Like

OHHHHHHH, I get it now. thank u so much

u too skellyton and deepblue. Thanks y’all

1 Like

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