#no idea what parameters are in functions

1 messages · Page 1 of 1 (latest)

spring star
#

they make absolutely no sense at all please explain(im really new to scripting and trying to learn bad if i could get a mentor that would be awesome lol)

blazing fjord
#

What do you mean what parameters are in functions?

spring star
blazing fjord
#

A parameter in a function is an external (from the function) variable that makes itself equal to the given external variable.

#

For example:

spring star
blazing fjord
neat fractalBOT
#

studio** You are now Level 5! **studio

spring star
#

ok

neat fractalBOT
#

studio** You are now Level 2! **studio

spring star
#

tysm

timber fossil
#

I can help explain it to you like you are five

#

(if you want me to)

spring star
#

sure but im actually 15 lol

#

i understand most of the code

blazing fjord
#
local x = 1 -- External variable with value of 1
local b = 4 -- External var with value of 4

function calcUlate(par1, par2) -- this function has 2 paramaters of Its own, basically variables just for the function.
     local eq
     par1 + par2 = eq -- it calculates the parameters and makes the eq variable value the reuslt value

     return eq -- returns variable eq (returning is basically what the function gives when Its called)
end

calcUlate(x, b) -- Giving the parameters the variables value in order
spring star
#

it is genuinely makes me draw a blank

blazing fjord
#

And if its still too complicated

#

Its like the functions is saying to itself local par1 and local par2

timber fossil
#

Basically "parameters" in functions are like stuff you would like to be used in the function

#

say you would like to have a function to print a players name

#

function printPlayerName(player)

print(player.Name)

end

printPlayerName(game.Players.LocalPlayer)
blazing fjord
#

Okay wait look

timber fossil
#

The parameters are the variables passed to the function

spring star
#

sry but still doesnt make sense, i swear i have an irl nerf when it comes to this

runic apex
#

parameters are values that you give to a function

blazing fjord
#
function this(par1)
     print(par1)
end

this("Hello, World") --ehat u put here is equal to par1
spring star
#

now i just need to understand why you use it

runic apex
#

it's an example

#

there is no use

blazing fjord
blazing fjord
#

An event hapoens which returns some shit

#

And to save the returned shit u use parameters

#

That gey the value of treturned things

spring star
#

ok

#

so could u explain why they used it here:
thing.Equipped:Connect(function()
e = script.Parent.Parent.Humanoid:LoadAnimation(anim)
e.Looped = true
e.Priority = Enum.AnimationPriority.Action

e:Play()

end)

blazing fjord
#

Like fir examoke RemoteEvent returns in given order: the player, the players name

runic apex
spring star
#

oh shit mb

blazing fjord
#

S

#

Here tho

blazing fjord
#

RemoteEvent returns in order: Player, Player Name

#

So when the event is called and you want to save the reurned informsiton

#

And youre a normal human being

#

You write the connected function like this

#
:Connect(function(player, playerName)
runic apex
#

a parameter is a value that you define when calling the function, it can be pretty much, whatever you want

spring star
blazing fjord
#

Its the value of the oarameter that matters

runic apex
#

yes ik

spring star
spring star
#

so how do you change the value

runic apex
blazing fjord
blazing fjord
#

When you call the function this()

#

You can set the par1 value by typing inside the ()s

#

Ehen calling the funciton

runic apex
blazing fjord
#

Thats literaky what ive just said but better cause im sleepy asf

spring star
#

ok

#

i kind of get it

runic apex
#

if you use a :Connect(function() end), Roblox tells you what are the parameters if you hover it: (it says "child: Instance", I cropped it too much)

spring star
#

OMG IT CLICKED

#

WHAT EVER IS HAPPENING THE FUNCTON, THE INFO IS PASSED INTO THE PARAMATER

#

AND THEN YOU CAN PRINT IT OR WHATEVER

#

RIGHT?

#

@runic apex

#

@blazing fjord

blazing fjord
#

Yeah

#

Wait

spring star
#

?

blazing fjord
#

Bro the parameter is like the function calling the pineapple ananas when you call it pineapple

spring star
#

lol

#

alr

blazing fjord
#

For the finction its par1

#

For everybody else its soenthing

#

U are just giving value to the par1

#

Like

#

Ugh im briandead rn

#

game.Players.PlayerAdded returns the player that joined the game

#

When you connect it to a funciton

spring star
#

ooh alr

blazing fjord
#

The funciton can read the player

#

And you can set it as a parameter

#

game.Players.PlayerAdded:Connect(function(player)

#

PlayerAdded gives variabkes to a function in a mf dictionary

#

For pkayeradded its one variable

#

Which is the player

#

That joined

spring star
#

ok ok

#

so what if like

#

its 2 or 3 paramtere

#

parameters

#

what then?

blazing fjord
#

Then the order of the oarameter counts

#

Like

#

With remotevent :FireClient

#

Or whatever it was for the client to send an event to the server

#

It returns

#

The player

#

And the args

#

You gave

#

In the locla script

#

:FireClient(arg1, arg2, arg3)

#

And the server when registering

#

It collects the args in ordrr

#

So it has to be 1 2 3

#

And not 2 1 3

#

Or else end of eorld

#

So

#

Idfk remember the registering shit

#

So imma just type

runic apex
#

order is important, if you put wrong things, script will not work

spring star
#

oooohh ok

neat fractalBOT
#

studio** You are now Level 3! **studio

spring star
#

i get it

blazing fjord
#

:OnClientEvent:Connect(function(player, arg1, arg2, arg3)

#

It reurns player and srgs

#

in give rorder

#

So if the args are

#

true, false, "Hello"

#

Itll teturn

#

Player, true, false, "Hello"

#

player, arg1, arg2, arg3

#

You can name the args however the fuck u wsnt

#

But the order doesnt change

runic apex
#

I think you're overexplaining

neat fractalBOT
#

studio** You are now Level 4! **studio

runic apex
#

bro gonna give up on scripting

blazing fjord
#

Its

#

4 am

#

Im taking a break

#

From

#

Shit

spring star
#

ur good

#

take ur brake

blazing fjord
#

Anyway

#

Like

runic apex
#

in my example, if I put a string ("hello") where I need to put the parent (game.Workspace), the script will end and return an error in the console saying that:

#

there are ways to prevent that from happening

blazing fjord
#

:FireClient(true, 13, "Hello")

:OnClientEvent:Connect(function(player, arg1, arg2, arg3)

#

arg1 = true

#

arg2 = 13

#

arg3 = "Hello"

#

And since u can name this shit however u want

#

And onky shit that natters is order

#

U can

runic apex
blazing fjord
#

:OnClientEvent:Connect(function(player, arg2. arg1, arg6)

#

arg2 = true

#

arg1 = 13

runic apex
#

calm down

blazing fjord
#

arg6 = "Hello"

runic apex
#

it's 4 am

blazing fjord
#

3 hours to go

runic apex
#

@spring star, did my explanations helped at all?

spring star
#

yes it did

runic apex
#

ok cool

#

so you know what parameters are now?

spring star
#

yea mostly

runic apex
#

ok

blazing fjord
#

A parameter is basically like placeholder values that you give into the function, then when you call the function, the placeholder parameters are turned into these values,

neat fractalBOT
#

studio** You are now Level 6! **studio

runic apex
#

most of stuff, you're going to find out by making random shit on Studio like everyone else

spring star
#

lol yea

blazing fjord
#

Its not that hard

#

Im onky like

#

1 year into luau and

#

I already made dquid game

spring star
#

oh fr?

#

lemme check it out

blazing fjord
#

The group owner of the studio i worked eith this on deketed it

runic apex
#

I'm only, 3y+ into luau (I think), and have made no finished product

blazing fjord
#

Now theyre making some

#

Squid game srason 2 shit eithout md

#

Me

spring star
#

dam

#

sry to hear that

blazing fjord
#

Owners user is obidientdev

#

Or

#

Obbydient

#

Wtv

#

Yeah Obbydient

spring star
#

yea ig

#

i just get overwhelmed when i see a single script with like 2k lines of code

#

like how do you even know how to do that

blazing fjord
#

Just patiennce

#

Is mostly ehat u need here

runic apex
blazing fjord
#

YandereSim

runic apex
#

I learned a bunch of stuff by making... "some programs"... and it really helped me into scripting better, but now, anti-cheat is active, and I havn't used anything like that since then. but still, learning new stuff was pretty cool

#

(just so y'all know, I wasn't making those "programs" on "competitive" games, only on garbage games that were only pure and boring farm)

blazing fjord
#

I just made newer versions of a game that calls you gay and kicks you out

#

Adding sm stuff I got pro

runic apex
blazing fjord
runic apex
#

oh