#function() help
1 messages · Page 1 of 1 (latest)
data u pass in when u call the function
Arguments
hiiii so i suck what’s an argument
but sometimes you can just put like words inside it
what happens then
i heard those are called strings or variables or is that smth else
You can make x be anything
😭
Yea
Text is string
Variable is x
You're just setting variable x to whatever you put when calling a function
i saw something like
part.Touched:Connect(function(fire)
what would fire be
In this case fire is depending what event you connect to.
In case of touched the fire will be what touched the part
so if i were to print out fire i would get the name of the thing touching the part?
yep
** You are now Level 8! **
alright so a function is just any block of code where you can "call" the function to use that block of code
it makes your code more reusable since you wont have to write the same piece of code in multiple different areas
so events each have their own parameters that gives your more information about that event so for the touched event, it would be useful to know what touched the part
okay i think i understand what it is on that end
but like what’s a parameter exactly
😭
i’m trying i’m swear i don’t know what it means
parameters are the placeholders values to send data to a function and they shouldnt be confused with another term known as arguments
so
function myFunction(num1, num2)
print(num1 + num2)
end
myFunction(1,2) -- prints 3
you can send in your own data (known as arguments) to functions so those functions can operate on that instead of hardcoded values
imagine it was this instead:
function myFunction()
print(1+2)
end
myFunction()
you dont have much flexibility here because you cant change what the function does
alright so parameters are the terms inside the () and the arguments are the data you send in
okay i’ll try to figure that out myself somehow
so in the example ive given you, num1 and num2 are parameters and 1,2 are arguments
so the myFunction(1,2) the parenthesis is an argument?
ohh
are there any more uses for parenthesis besides that
😮💨
yeah but most of them you wont need to know for now
😭
i mean that would be helpful
you don’t need to explain i’ll try to figure it out myself
they can be used to make an expression more clear so
local speed = distance / time
if (speed > 20 and speed < 30) then
print(speed)
end
paranthesis can be used to change order in which expressions are evalauted so
print(2+3*4) -- prints 14
print((2+3)*4) -- prints 20
theres also IIFE functions where a function runs as soon as its defined but idk if thats a feature in lua
thats all i know but you could prolly find more using gpt or sum
wait is there a reason why there’s a ) behind time
oops
i’d cry if that ) is necessary 😭
is ‘and’ recognised in luau
thanks by the way you’re helping me a ton 🥹
yep
it just makes it so both expressions have to be true for it to run, so you see how theres speed > 20 and speed < 30 both of those need to be true for the if statement to run
so and carries the same meaning as and?
like the english and
is the same as luau’s and
thanks mate it’s a huge headache but i think i’ll be ready to fully script a working game tomorrow 😎
** You are now Level 6! **
jokes aside thanks for your help