#function() help

1 messages · Page 1 of 1 (latest)

vital valve
#

for context, i have absolutely zero prior experience with coding in general. i have also tried checking with multiple resources and still can’t figure this out.

in function(), what does the parenthesis generally hold?

gaunt notch
#

data u pass in when u call the function

vital valve
#

hiiii so i suck what’s an argument

rich pollen
#

function myfunction(x)

Means if you do myFunction(123)

#

X will be 123

#

Inside it

vital valve
#

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

rich pollen
vital valve
#

😭

rich pollen
#

Text is string

#

Variable is x

#

You're just setting variable x to whatever you put when calling a function

vital valve
#

i saw something like

part.Touched:Connect(function(fire)

what would fire be

rich pollen
vital valve
#

so if i were to print out fire i would get the name of the thing touching the part?

boreal orchidBOT
#

studio** You are now Level 8! **studio

vital valve
#

i think i’m starting to understand it like a lil more

#

thanks

paper shadow
#

it makes your code more reusable since you wont have to write the same piece of code in multiple different areas

vital valve
#

ohh

#

okay i still don’t quite understand wtf () is

paper shadow
vital valve
#

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

paper shadow
#

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

vital valve
#

oh my gosh 😭

#

what’s an argument

paper shadow
vital valve
#

okay i’ll try to figure that out myself somehow

paper shadow
#

so in the example ive given you, num1 and num2 are parameters and 1,2 are arguments

vital valve
#

ohh

#

are there any more uses for parenthesis besides that

#

😮‍💨

paper shadow
vital valve
#

😭

paper shadow
#

and probably wont use them for now

#

if u really wanna know i can tell u

vital valve
#

i mean that would be helpful

#

you don’t need to explain i’ll try to figure it out myself

paper shadow
# vital valve i mean that would be helpful

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

vital valve
vital valve
#

i’d cry if that ) is necessary 😭

#

is ‘and’ recognised in luau

#

thanks by the way you’re helping me a ton 🥹

paper shadow
#

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

vital valve
#

so and carries the same meaning as and?

paper shadow
#

idrk what u mean

vital valve
#

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 😎

boreal orchidBOT
#

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

vital valve
#

jokes aside thanks for your help