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 » Scripting Helpers
Home Search
 

Re: Return

Previous Thread :: Next Thread 
UFAIL2 is not online. UFAIL2
Joined: 14 Aug 2010
Total Posts: 6905
27 Jan 2012 05:44 PM
Will someone explain to me how to use 'return'?
Report Abuse
Jammintoad is not online. Jammintoad
Joined: 08 Feb 2009
Total Posts: 10239
27 Jan 2012 05:48 PM
Return can be used to stop a function.
function onTouch(hit)
print("Function started yay")
return
print("This should not display becuz of return")


script.Parent.Touched:connect(onTouch)



It can also be used to return bool values from functions, I know less about this though, but I believe it goes like this.


function check()
player = script.Parent
if player:findFirstChild("Humanoid") then
return true
else
print("No humanoid :(")
end
end


function onTouchtwo(hit)
print("Function started yay")
if check() then
print("Der was a humanoid yaaaaaaa")
end
end


script.Parent.Touched:connect(onTouchtwo)
Report Abuse
UFAIL2 is not online. UFAIL2
Joined: 14 Aug 2010
Total Posts: 6905
27 Jan 2012 05:59 PM
Thanks.
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
27 Jan 2012 06:02 PM
return ends a function and sends any data after it back to the calling function.

function getOne()
return 1
print("This will never print")
end

local number = getOne()
print(number)

>1

Return can be used for any datatype.
Report Abuse
Cyrok is not online. Cyrok
Joined: 11 Jan 2012
Total Posts: 630
27 Jan 2012 08:46 PM
Return is a statement that immediately stops the function and gives you the optional choice of making the function it's inside of return any data type value.

function cout()
    print("Hello ")
    return "World!"
    print("Fin.")
end

print(cout())

Output: Hello World!
Report Abuse
socccerstar is not online. socccerstar
Joined: 23 Aug 2008
Total Posts: 489
27 Jan 2012 08:51 PM
If you use return by itself, it stops the function it's in.

If you use return followed by a variable or data type, then wherever you called the function will "be" that piece of data. For example:

function func1()
return 5
end

print(func1())

Would print "5".

If you want to check if the function returned something, you would want to use "not", which works like this:

function func1()
return
end

function func2()
return nil
end

function func3()
return false
end

function func4()
return true
end

if not func1() then
print("func1")
end

if not func2() then
print("func2")
end

if not func3() then
print("func3")
end

if func4() then
print("func4")
end

Would print:
func1
func2
func3
func4

Make sense?
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
27 Jan 2012 10:10 PM
Return holds a value.
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
27 Jan 2012 10:16 PM
it can return multiple values too!

local mr = math.random
function getThreeRandomNumbers(max)
max = max or 100
return mr(max),mr(max),mr(max)
end

v1,v2,v3 = getThreeRandomNumbers()
print(v1,v2,v3)

> 31 85 4
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
27 Jan 2012 10:25 PM
@blue

Did you actually test that?
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
27 Jan 2012 10:26 PM
lolnope.avi
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
27 Jan 2012 10:28 PM
lol just tested it and it works, lol im so good i dont need to test, i get it right first time every time :P jks. :P
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
27 Jan 2012 10:28 PM
-_-

Erm....Ok then...
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
27 Jan 2012 10:29 PM
but i dont normally test examples because im pretty fluent with Lua, because 95% of the time the tests are right, so i dont test them unless someone says that it doesn't work :P
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
27 Jan 2012 10:29 PM
wait a sec... you were that troll that said that my lighting place was sucky! >:O
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
27 Jan 2012 10:31 PM
Well I am a troll and I do suxonthings....
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
27 Jan 2012 10:32 PM
ya, but I actually thought I had someone with a better lighting place (apart from oysi's realtime lighting) so I went to that persons place and it sucked >.< lol
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
27 Jan 2012 10:34 PM
Lol. Yeah. One time there was this guy that thought his soccer game was better than mine but yet there was seriously NO SCRIPTS in the game XD
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
27 Jan 2012 10:39 PM
lol, i can see why you have the troll face on your shirt :P
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
27 Jan 2012 10:44 PM
This is a troll face? I thought it was a blueymaddog face :)
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
27 Jan 2012 10:54 PM
nope, im gonna put on my blueymaddog face now, you cant take me serious when I put my bluey face on even though im in a buisness suit with a fedora :P
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
27 Jan 2012 11:00 PM
LOL!!!YOU LOOK LIKE A SNOOKIE WITH CHEST MUSCLES :P
Report Abuse
LuisPambid is not online. LuisPambid
Joined: 31 Mar 2011
Total Posts: 532
28 Jan 2012 04:21 AM
Bluey, Change Topic lol xD
Report Abuse
LuisPambid is not online. LuisPambid
Joined: 31 Mar 2011
Total Posts: 532
28 Jan 2012 04:24 AM
Return means making the function return an object

function Me()
Me = game.Players.LuisPambid
return Me
end

Luis = Me() --Making the function to be a variable
Luis:Destroy() --Removes ME!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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