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 PLEASE HELP!!!

Previous Thread :: Next Thread 
Zeloi is not online. Zeloi
Joined: 27 Sep 2010
Total Posts: 1143
10 May 2014 09:07 AM
Ok so I've been scripting for maybe around 1-2 years and have NEVER found out how to use return and when to use it.

Can some of you explain return in-depth?

Thanks!
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
10 May 2014 09:09 AM
myFunction = function(x, y)
return x + y
end

myNumber = myFunction(10,25)
print(myNumber) --> 35
print(myFunction(10,20)) --> 30
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
10 May 2014 09:09 AM
In a nutshell:
http://wiki.roblox.com/index.php/Function#Using_Return
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
10 May 2014 09:09 AM
function is_it_true(text)
if text == "yes" then
return true
elseif text == "no" then
return false
end
end


print(is_it_true("yes"))
>true



function getStringFromNumber(number)
if number == 1 then
return "lolz"
else
return "lol ASDSD"
end
end

print(getStringFromNumber(1))
>lolz
Report Abuse
Zeloi is not online. Zeloi
Joined: 27 Sep 2010
Total Posts: 1143
10 May 2014 09:11 AM
Explain a bit?

I don't need a script I just need an explanation
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
10 May 2014 09:12 AM
Did you read trioxide's link? It explains it.

From the link:

When return is called, a couple things happen:

The function stops executing; also note that you cannot have any statements immediately after return or you will receive an error.
The function becomes somewhat like a variable, holding the value(s) returned. Like this you can "set" a variable to what the function returns.
Report Abuse
Zeloi is not online. Zeloi
Joined: 27 Sep 2010
Total Posts: 1143
10 May 2014 09:13 AM
so return prints a number value?
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
10 May 2014 09:15 AM
Nononono, return "gives" whatever you want it to give, from the function to the scope you call it in.

Lets say we have a function like this:

function getPlayerFromName(name)
if game.Players:findFirstChild(name) then
return game.Players[name] --returns the player instance
end
end


player = getPlayerFromName("StealthKing95")
player:Kick()
Report Abuse
lewisw60 is not online. lewisw60
Joined: 27 Nov 2008
Total Posts: 193
10 May 2014 09:16 AM
If you return a function, then you can call a function using a variable.

function foo()
bar = 'anything'
return bar
end

x = foo()
print(x)

That would print 'anything'
Report Abuse
Zeloi is not online. Zeloi
Joined: 27 Sep 2010
Total Posts: 1143
10 May 2014 09:19 AM
xD IM SOOOOO Confused im sorry! qq
Report Abuse
lewisw60 is not online. lewisw60
Joined: 27 Nov 2008
Total Posts: 193
10 May 2014 09:22 AM
Basically you can give the actual function a value. Almost like a variable.
so
function yes()
return 1
end

would make the function yes worth 1
you could go on to say
x = yes
so now x = 1 because yes = 1
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
10 May 2014 09:23 AM
^ small error here. Youre actually setting x to the function, not what its returning.


change x = yes

to

x = yes()
Report Abuse
Zeloi is not online. Zeloi
Joined: 27 Sep 2010
Total Posts: 1143
10 May 2014 09:24 AM
Ok I get it but why would you use this?

would you use it to upper a value like if you where making a tycoon?
Report Abuse
lewisw60 is not online. lewisw60
Joined: 27 Nov 2008
Total Posts: 193
10 May 2014 09:24 AM
typo :P
Report Abuse
Zeloi is not online. Zeloi
Joined: 27 Sep 2010
Total Posts: 1143
10 May 2014 09:31 AM
What would I use this for?
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