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

What does return do , is it used to check the script?

I saw alot of post but I still dont get what does return do. I have a rough idea , is it for checking the script.

Lets say this is the script. Is returned used to check the "-- Script" if it works?

local function test()
print("start")
-- Script
return "check"
end
local a = test()
print(a)

1 answer

✓ Accepted answer

Formally, the definition of the return keyword is "a statement that tells the program to leave the subroutine and return to the return address". Essentially, if we wish to return a result from a computation or various other scenarios that is concluded from a function, we use this keyword to define what we wish to give. See this example of it's potential applications:

local numberA = 5
local numberB = 2

local function multiplyNumbers(a,b)
	return a * b
end

local result = multiplyNumbers(numberA, numberB)

This will return the multiplication of parameters A and B to wherever this function—or the fancy term "subroutine"—was called, as aforementioned above. To break this down, this is what's occuring:

local result = a * b
local result = 10

An easy way to grasp return, is to see is as the "give back" keyword. Before I finish, let's see another example:

local hello, world = "Hello", "world!"

local function concatenateStrings(a,b)
	return tostring(a..' '..b)
end

print(concatenateStrings(hello, world)) --> 'Hello world!'

2 comments

0

Thank you so much I get what you mean but what is sub routine?

0

A subroutine is the formal definition of a "function".

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