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

What does return mean? What do you use it for? Why is it useful?

Asked by 3 years ago

Hello guys. I have question. I can't understand what return means. So I'm wondering what return is. What is return? Why do you use it? Why is it useful?

I want to know that. If you can help me, thank you,

Ducksneedhelp - New Scripter

3 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

https://www.lua.org/pil/4.4.html

Please refrain from asking these kinds of questions on the forums. The forums are more meant for questions that you can't just search up easily.

Ad
Log in to vote
0
Answered by
VitroxVox 884 Moderation Voter
3 years ago
Edited 3 years ago

Hello returns are useful for a lot of things like if using a RemoteFunction you can example as : Ask the server for the clients money in the data base or information about the server , server-sided things, etc.

function getme()
    return 1+2
end

print(getme) --would print "3"

function myname()
    return game:GetService("Players").LocalPlayer.Name
end

Well basically it's in the name "return" that's what it's used for to return strings,values,int's,tables, even functions sometimes depends on how you want it and what you do with it.

or as Crazyman32 said :

Example from real life:

You go to a restaurant and order a sandwich and a drink. A bit later, you receive the sandwich and drink. In other words, you gave the restaurant input (your order) and it in turn gave an output (sandwich and drink).

The process of the restaurant outputting would be what return does. In this analogy, you are the caller of the function, and the restaurant is the function.

function Restaurant:OrderFood(orderInfo)
   -- Do some stuff to figure out the actual food
   return food
end

-- You, the customer:
local myFood = Restaurant:OrderFood("Sandwich", "Water")

Hope this helps, cheers!

0
hey just wondering is return basically for checking something? like printing? RebornedSnoop 175 — 3y
0
It's for returning information. VitroxVox 884 — 3y
Log in to vote
-1
Answered by 3 years ago

https://www.google.com

Answer this question