How to Read/understand what is inside parameters?

Well to me parameters are things that can be overridden/used for later.
even if it’s not today’s question I also wanted to know if what I said is true.

So I wanted to know how to read and understand the text inside brackets:

Understand Parameters
Understand Parameters 2

and more complicate:

Of course these are just examples.

any help will be appreciated !

For this: (I may have misunderstood something however)

pairs is simply looking for a Table as stated below the Parameters

When People use GetChildren or GetDescendants:
GetChildren returns a table of the children within a Object

GetDescendants returns a table of Every single Item within a Object

Example:

TableOfStuff = {"Apple", "Orange"} -- Table

for i, p in pairs(TableOfStuff) do
print(i) -- Prints the Number of Objects
print(p) -- prints the Object
end

I may be wrong about this so feel free to correct me

The Parameters are just syntax stuff

I believe you can learn more about it here

so is just all arguments passed into the function

for example print("hello", "hello2") will output hello hello2 the print function will automatically take alll of the arguments (arguments are things separated by commas passed into a function) and combine them into one string

when you see a colon after something, for example name: string that is is the type the function expects it to be

for example: a function called FindFirstChild expects a string for the name of the child you wish. a string is something surrounded by quotes, double or single. :FindFirstChild("name here")

when things get more complicated such as the pairs function. the types are weird looking because of how roblox set it up.

pairs() takes any tupe of table and that is what the type (thing after the colon (:)) is saying

now when you see a question mark after a type that means its an optional argument

for example: the Instance.new() function. it takes a required argument of the class and an optional argument of its parent to set to. Instance.new(className: string, parent: Instance?)

finally the colon at the very end of the function print(...: T...): () what it is, is whatever the function returns

for example: a function that returns a number would look like this function(): number

here are some examples of custom functions that use this type stuff

-- function that takes a list of BaseParts and returns a boolean (true/false)
function AnyTouching(list: {BasePart}): boolean

-- function that searches for a name (idk these are just examples) and returns a bool if found
function Search(name: string): boolean
2 Likes

The main format of the parameters are

Name: Type

take CollectGarbage for example, Mode is the name of the parameter, and string is the type of the parameter

for Print, it uses Variatic types which is just a list of untracked parameters passed in

local function VariaticFunction(...)
  for i,v in pairs({...}) do
    print(i, v)
  end
end

pairs you need a rocket science degree in typechecking to understand and @bIorbee explains it nicely

2 Likes

I appreciate your feedback. but I’m going to sleep soon so I’ll read tomorrow if you don’t mind

1 Like

Parameters are just bits of data (variables). Those bits of data can be different types.

You can pass variables to sections of purposeful code (functions) as parameters (/ arguments).

These parameters are local to the function they’re passed to. After the function exits (returns), those variables are collected and garbaged (garbage collection), though this is an oversimplification.

print accepts parameters. Within Lua, there’s a function:

function print(...)
    for k, v in pairs({...}) do
        io.write(v)
    end
end

Again, an oversimplification, though fundamentally parameters are just variables local to whatever they’re being passed to.

When u say :Instance.new(className: string, parent: Instance?)

so that means that the first argument is what the parameters expects from us. And that after the comma it’s optional?

And when the parameters include : () this mean we can put any thing and we don’t care what is inside bracket , and finnaly if we don’t have : ()
but : number this mean we need to put a number inside the bracket.

am i wrong?

: () expects a function to be passed or a callback

and yes the argument after the comma is optional

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