| |
|
|
| 01 Jan 2013 04:29 PM |
http://wiki.roblox.com/index.php/Return#Using_Return
Return gives you a value from something
for example
function ReturnAddedNumber(number, add) addednumber = number + add return(addednumber) end
print(ReturnAddedNumber(2, 4))
will print 6, because the function ReturnAddedNumber returns 2 plus 4 |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2013 04:30 PM |
| it also stops the function. |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2013 04:31 PM |
Here is what I have made from experimenting.
function hi() return ("hello") end
a = hi()
if a == ("hello") then print("hi") wait(1) end
|
|
|
| Report Abuse |
|
|
|
| 01 Jan 2013 04:32 PM |
| that would print "hi" because the value "a" gets set to "hello" from the function hi() |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2013 04:33 PM |
Wait, can't you just use a variable instead of using return, like this:
x = ("hi")
function wow() return ("woah") end
a = wow() |
|
|
| Report Abuse |
|
|
| |
|
DrHaximus
|
  |
| Joined: 22 Nov 2011 |
| Total Posts: 8410 |
|
|
| 01 Jan 2013 04:39 PM |
| A return value is basically a value the function gives the function that called it. |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2013 04:46 PM |
| Can anyone please answer my question? |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2013 04:48 PM |
function omg() return 7 end
a = omg() print(a) > 7
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]- |
|
|
| Report Abuse |
|
|
DrHaximus
|
  |
| Joined: 22 Nov 2011 |
| Total Posts: 8410 |
|
| |
|
sayhisam1
|
  |
| Joined: 25 Nov 2009 |
| Total Posts: 2092 |
|
|
| 01 Jan 2013 04:50 PM |
I believe you can do something like
function add() a = 1+1 if a = 1+1 then return true end
if true do print("Math is correct. World isn't ending.") end
with return Corrrect me if I am wrong though, I haven't dabbled much in the usage of return... |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2013 04:52 PM |
>if a = 1+1 then if a == 1+1 then |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2013 04:52 PM |
Correction...
function add() a = 1+1 if a = 1+1 then return true end end
if add() == true then print("Math is correct. World isn't ending.") end |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2013 04:52 PM |
| Yeah what cody said too. Forgot that. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 01 Jan 2013 04:54 PM |
Return is mainly used for returning an instance from a function. You CAN make it a variable but you can end up having a whole bunch of variables.
With Variable: lol = ""
function hi() lol = "hi" end
hi() print(lol)
Without Variable: fuction hi() return hi end
print(hi)
It can also be used to stop a function from continuing, exmaple: function LongCrazyScript() print("HI") print("HI2") print("HI3") print("HI4") print("HI5") return print("HI6") print("HI7") print("HI8") end
LongCrazyScript()
Output: HI, HI2, HI3, HI4, HI5 |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2013 04:55 PM |
That would not work, there cannot be code after a "return."
I think the question is answered enough.... |
|
|
| Report Abuse |
|
|
|
| 01 Jan 2013 05:08 PM |
@wafles
function stuff(morestuff) if morestuff < 5 then return "Less than 5"
else for i = 1, 5 do print(i) end end end
stuff(6) *prints 1-5*
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]- |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 01 Jan 2013 05:13 PM |
@wafles26122 Ohh yea, my bad. |
|
|
| Report Abuse |
|
|