#no idea what parameters are in functions
1 messages · Page 1 of 1 (latest)
What do you mean what parameters are in functions?
A parameter in a function is an external (from the function) variable that makes itself equal to the given external variable.
For example:
can you please explain that im simpler terms, i am really tired LOL
Ill just show you
** You are now Level 5! **
ok
** You are now Level 2! **
tysm
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
it is genuinely makes me draw a blank
And if its still too complicated
Its like the functions is saying to itself local par1 and local par2
same
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)
Okay wait look
The parameters are the variables passed to the function
sry but still doesnt make sense, i swear i have an irl nerf when it comes to this
parameters are values that you give to a function
function this(par1)
print(par1)
end
this("Hello, World") --ehat u put here is equal to par1
this makes sense
now i just need to understand why you use it
Sometimes like in the sc u gave
^
An event hapoens which returns some shit
And to save the returned shit u use parameters
That gey the value of treturned things
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)
Like fir examoke RemoteEvent returns in given order: the player, the players name
there are no parameters in that script
oh shit mb
There are no par
S
Here tho
Back to this
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)
a parameter is a value that you define when calling the function, it can be pretty much, whatever you want
ye i see this alot
The name doesnt matter
Its the value of the oarameter that matters
yes ik
so its like having a local in a function but its for the function like:
part.touched:connect(function(hit)
ohh ok
so how do you change the value
here, hit is a BasePart, if you want, you can do this:
part.touched:connect(function(hit: BasePart)
to make it easier to read
Like ive said
.
When you call the function this()
You can set the par1 value by typing inside the ()s
Ehen calling the funciton
the parameters are defined when you call the function, here, the parameter is game.Workspace.Part
Thats literaky what ive just said but better cause im sleepy asf
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)
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
?
Bro the parameter is like the function calling the pineapple ananas when you call it pineapple
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
ooh alr
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
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
order is important, if you put wrong things, script will not work
oooohh ok
** You are now Level 3! **
i get it
: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
I think you're overexplaining
** You are now Level 4! **
bro gonna give up on scripting
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
: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
if you do this, the script will stop and prevent it from breaking.
calm down
arg6 = "Hello"
it's 4 am
3 hours to go
@spring star, did my explanations helped at all?
yes it did
yea mostly
ok
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,
** You are now Level 6! **
most of stuff, you're going to find out by making random shit on Studio like everyone else
lol yea
The group owner of the studio i worked eith this on deketed it
I'm only, 3y+ into luau (I think), and have made no finished product
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
Read it like a book
Just patiennce
Is mostly ehat u need here
don't worry about scripting good, some games make thousands of active players while making really bad scripts
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)
I just made newer versions of a game that calls you gay and kicks you out
Adding sm stuff I got pro
I wasn't there since the beginning of the conversation, what's that game?
This IS the beginning of the conversation
oh
