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 |
|
|
|
| 30 Aug 2013 02:37 AM |
| Me too. return probably is not that vital to a script, or what it does. |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 30 Aug 2013 06:36 AM |
| i un't. What's the pnt of doin dis? |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 30 Aug 2013 07:27 AM |
| it makes math easier, that's for sure |
|
|
| Report Abuse |
|
|