Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is a function?

I asked my friend what a function is and what he told me wasn't really a good example, Any help?

1 answer

✓ Accepted answer

Functions can be confusing from a conceptual standpoint. These analogies may help you.

A function as a subroutine - You can think of a function as a "subroutine" a block of code that can be executed again and again. Why do we want this? Because it reduces copying and pasting.

function YouCanRepeatMe()
	print("Hi.!")
	print("I like saying hi!")
	print("Hi there!")
end
 
YouCanRepeatMe()
YouCanRepeatMe()
YouCanRepeatMe()
YouCanRepeatMe()

You can see here, that, instead of repeating the lines inside of the function 12 times, you can repeat it only 4 times, each time you call it. This is a subroutine. You gave it a name, YouCanRepeatMe, and you told it what to do. Programming is all about automating repetitive tasks! I'm sure you can divide 234.351 to 23.1225234, but it's much easier to type it into a calculator! That's what this is all about!

This discussion is preserved as it was. New answers, comments, and votes are closed.