Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is the point of a function? What does it do? Do you need them?

Asked by 6 years ago

I think I know what they are, I just want to make sure. Plus this may help others!!!

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

A function is a chunk of code that you encase that will only run when called on. for instace

--this is how you make a function with the name 'printSomeLines'
function printSomeLines()
    print('hello')
    print('World')
end

The code in this function will only run if the function is called upon like so

--since we already created the function above doing this will run all of the code inside of it
printSomeLines()

Alot of events in this game allow you to connect a function to it when they trigger like

--This connected function will run whenever the button is clicked
button.ClickDetector.MouseClick:Connect(printSomeLines)

However, you dont have to create your own function and call it, you can make an anonymous function and put it in the event like so

button.ClickDetector.MouseClick:Connect(function()
    print('Hello')
    print('World')
end)
0
Yep, super helpful! Use em all over the place haha iiDoge_Legend 3 — 6y
0
yes functions store code which can be used in the future User#19524 175 — 6y
0
hey, I wrote the first answer on this question, sorry it was really bad and not helpful, I was in a rush and just tried to help, I know the answer sucked. FlippinAwesomeCrew 62 — 6y
Ad

Answer this question