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: Srsly, I never got return

Previous Thread :: Next Thread 
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
30 Aug 2013 02:35 AM
It obviously returns something, but I still don't get it.
Blah
Report Abuse
DragonODeath is not online. DragonODeath
Joined: 02 May 2011
Total Posts: 1252
30 Aug 2013 02:37 AM
Me too. return probably is not that vital to a script, or what it does.
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
30 Aug 2013 02:39 AM
I'm actually going back to add depth to my knowledge so far. I'm filling in the gaps, oh I doubt that its something you'll just pass on. I see it on almost every professional script.

This returns a humanoid

return game.Players:children().Character.Humanoid

other than that and adding two variables, nosebleed.
Report Abuse
Desperian is not online. Desperian
Joined: 07 Feb 2012
Total Posts: 3371
30 Aug 2013 02:49 AM
It merely allows for you to get something out of a function, nothing more or less (It also stops the execution of the function when it's called).

function Meh(Te)
if Te == "Hey!" then
return true, Te
else
return false, Te
end
end

local State, Given = Meh("Hey!")

print(Meh("Hey!")) --> true Hey!
print(State, " :: ", Given) --> true :: Hey!


Report Abuse
IamAwesome777 is not online. IamAwesome777
Joined: 18 Jul 2011
Total Posts: 2640
30 Aug 2013 06:31 AM
return is one of the most useful things in programming/scripting.

http://wiki.roblox.com/index.php/Return#Using_Return


local function SomeFunction()
return "Applesssssss" -- here it allows you to assign a variable (In this case 'apple') to the return statement
print("Hooray") -- won't execute because when you call return, the function is exited immediately.
end

local apple = SomeFunction()
print(apple) --> Applesssssss
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
30 Aug 2013 06:34 AM
Thx guys x0x0
Report Abuse
IamAwesome777 is not online. IamAwesome777
Joined: 18 Jul 2011
Total Posts: 2640
30 Aug 2013 06:34 AM
And, as Desperian demonstrated, you can return multiple items.

local function Hello(Text)
return "Function called",Text--return 2 objects. they can be strings, integers, tables, booleans or roblox objects.
end

local Func,Text = Hello() -- assign 2 variables to the 2 values returned from the Hello function

print(Func,Text) --> Function Hello
Report Abuse
IamAwesome777 is not online. IamAwesome777
Joined: 18 Jul 2011
Total Posts: 2640
30 Aug 2013 06:35 AM
Whoops.....

local Func,Text = Hello("SomeText") --assign 2 variables to the 2 values returned from the Hello function

print(Func,Text) --> Function SomeText
Report Abuse
DragonODeath is not online. DragonODeath
Joined: 02 May 2011
Total Posts: 1252
30 Aug 2013 06:36 AM
i un't. What's the pnt of doin dis?
Report Abuse
IamAwesome777 is not online. IamAwesome777
Joined: 18 Jul 2011
Total Posts: 2640
30 Aug 2013 06:47 AM
return is actually not a very advanced element of programming/scripting, it just takes some simple logic to understand it.
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
30 Aug 2013 07:05 AM
Sometimes its too simple that it wouldnt make sense. Like feeding a lion curry. Maybe, idk
Report Abuse
Absurdism is not online. Absurdism
Joined: 18 Jul 2013
Total Posts: 2568
30 Aug 2013 07:22 AM
Actually, it makes a lot of sense. Return /is/ one of the most useful things in Lua. Compare the two excerpts of code that return to the interpreter the same:

f = 5

g = function(x)
f = f + x
end

g(3)
print(f)

-- and:

g = function(x)
return 5 + x
end

print(g(3))

Also, I've written many other useful things with it:
string.tweenParams = function(s, sx0, sx1, inclusive)
return inclusive and s:sub(s:find(sx0)+0, select(1, s:find(sx1))) or s:sub(s:find(sx0)+1, select(1, s:find(sx1)-1)) or false
end

exemplar = 'Hello, world!'
print(exemplar:tweenParams(',', '!'))
print(exemplar:tweenParams(',', '!', true))
Report Abuse
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
30 Aug 2013 07:27 AM
it makes math easier, that's for sure
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