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: Can anyone explain to me what return is?

Previous Thread :: Next Thread 
TehPwnzerLord is not online. TehPwnzerLord
Joined: 15 Sep 2010
Total Posts: 2661
01 Jan 2013 04:25 PM
Please?
Report Abuse
wafles26122 is not online. wafles26122
Joined: 14 Jun 2010
Total Posts: 958
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
yomamadude6 is not online. yomamadude6
Joined: 21 Nov 2009
Total Posts: 2151
01 Jan 2013 04:30 PM
it also stops the function.
Report Abuse
TehPwnzerLord is not online. TehPwnzerLord
Joined: 15 Sep 2010
Total Posts: 2661
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
wafles26122 is not online. wafles26122
Joined: 14 Jun 2010
Total Posts: 958
01 Jan 2013 04:32 PM
that would print "hi" because the value "a" gets set to "hello" from the function hi()
Report Abuse
TehPwnzerLord is not online. TehPwnzerLord
Joined: 15 Sep 2010
Total Posts: 2661
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
TehPwnzerLord is not online. TehPwnzerLord
Joined: 15 Sep 2010
Total Posts: 2661
01 Jan 2013 04:36 PM
Anyone please?
Report Abuse
DrHaximus is not online. 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
TehPwnzerLord is not online. TehPwnzerLord
Joined: 15 Sep 2010
Total Posts: 2661
01 Jan 2013 04:46 PM
Can anyone please answer my question?
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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 is not online. DrHaximus
Joined: 22 Nov 2011
Total Posts: 8410
01 Jan 2013 04:48 PM
Return "hi"
Report Abuse
sayhisam1 is not online. 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
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
01 Jan 2013 04:52 PM
>if a = 1+1 then
if a == 1+1 then
Report Abuse
wafles26122 is not online. wafles26122
Joined: 14 Jun 2010
Total Posts: 958
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
wafles26122 is not online. wafles26122
Joined: 14 Jun 2010
Total Posts: 958
01 Jan 2013 04:52 PM
Yeah what cody said too. Forgot that.
Report Abuse
cntkillme is not online. 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
wafles26122 is not online. wafles26122
Joined: 14 Jun 2010
Total Posts: 958
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
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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 is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Jan 2013 05:13 PM
@wafles26122
Ohh yea, my bad.
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