generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: In what cases are returns used?

Previous Thread :: Next Thread 
JoeDev is not online. JoeDev
Joined: 04 Oct 2011
Total Posts: 6475
31 Jul 2017 09:12 PM
I might not fully understand, but it all seems like it can be done without the return function.
Is it an optimization thing? Or is there more.
Report Abuse
vivivio is online. vivivio
Joined: 23 Jan 2012
Total Posts: 707
31 Jul 2017 09:15 PM
its only used when the function is going to return something
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
31 Jul 2017 09:15 PM
If you want to have a block of code able to be called anywhere, make a function of it. However, what if you want output from that function based on certain inputs? That is when you would use return, to 'return' that output.
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
31 Jul 2017 09:15 PM
It's actually always used in a function, implicitly or not.


Report Abuse
Curite is not online. Curite
Joined: 28 Jan 2014
Total Posts: 60
31 Jul 2017 09:15 PM
Oh fu‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌ck me daddy!!!!!!!!
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
31 Jul 2017 09:18 PM
^Applause to the Roblox filter.
Report Abuse
JoeDev is not online. JoeDev
Joined: 04 Oct 2011
Total Posts: 6475
31 Jul 2017 09:21 PM
Is it to ensure its running properly?

Sorry, I am having a rough time.
Report Abuse
navycarrier is not online. navycarrier
Joined: 18 Feb 2014
Total Posts: 18
31 Jul 2017 09:22 PM
Used to return a value from a function to where you called it, an example:

fuction Add(a,b)
return a + b
end

local ReturnedValue = Add(5,2)

print(ReturnedValue) --This would then end up printing "7"
Report Abuse
JoeDev is not online. JoeDev
Joined: 04 Oct 2011
Total Posts: 6475
31 Jul 2017 09:24 PM
I think I understand, is this commonly used? I just want to make sure I completely understand before I continue my learning.
Report Abuse
BrendonTheWizard is online. BrendonTheWizard
Joined: 28 Jul 2010
Total Posts: 25709
31 Jul 2017 09:26 PM
a void method doesn't return anything and is very common

any other method does meaning you could pass an entire function in as a parameter

pseudocode that may or may not work:

functionA()
print("this will always return 5")
return 5
end

functionB(num)
print("this is a void method that won't return anything but its function is to multiply an integer by three")
print(num * 3)
end

functionB(functionA()); -- should print 15
Report Abuse
ExecutionMode is not online. ExecutionMode
Joined: 12 Jan 2015
Total Posts: 380
31 Jul 2017 09:27 PM
yes it is commonly used

it's also needed when you're working with modulescripts
http://wiki.roblox.com/index.php?title=API:Class/ModuleScript
Report Abuse
iiNemo is online. iiNemo
Joined: 22 Jul 2013
Total Posts: 2380
31 Jul 2017 09:29 PM
Okay so there are many cases, example.
while wait() do
if blah == true then
return
end
end
this is practically the same thing as break, but ya.
function Nemo()
return 5
end
print(Nemo())
Output: 5
Module scripts to return whats being called or whatever, I'm sure there are many others
Report Abuse
BrendonTheWizard is online. BrendonTheWizard
Joined: 28 Jul 2010
Total Posts: 25709
31 Jul 2017 09:30 PM
a function that does something and returns a boolean true/false can be especially useful
Report Abuse
BrendonTheWizard is online. BrendonTheWizard
Joined: 28 Jul 2010
Total Posts: 25709
31 Jul 2017 09:33 PM
outside of roblox if you get into any common object oriented programming language like java returns are highly necessary

module scripts in roblox are a great example of OOP and returns are necessary and added by default

the entirety of the module script can be done before it returns and only when it does return will the script that called it continue to run
Report Abuse
MICHEAL1988351 is online. MICHEAL1988351
Joined: 26 Jan 2015
Total Posts: 582
31 Jul 2017 09:40 PM
@unsub indeed returns are always used in functions whether you supply one or not.

From a low level perspective a function must always return to the instruction after the call to the function.

for example a procedure in assembly languages will always have a RET instruction in order to return the instruction pointer to the address of the instruction after the call to the procedure.

myproc PROC
PUSH EBP
MOV EBP, ESP
;do something crazy
MOV ESP, EBP
POP EBP
RET ;return
myproc ENDP

main PROC
PUSH EBP
MOV EBP, ESP
CALL myproc
MOV ESP, EBP
POP EBP
RET ;return
main ENDP

From a high level perspective like Lua, you would supply a return to one or more paths of your function to commonly return a value. Lets say that you wanted to return the sum of x and y in the following function, you can do so by returning it:

local function ReturnSum(x, y)
return x + y;
end
local result = ReturnSum(10, 15);
print(result); --will output 25.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image