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: What does return do?

Previous Thread :: Next Thread 
Jello715 is not online. Jello715
Top 100 Poster
Joined: 05 Feb 2008
Total Posts: 7491
25 Mar 2009 08:22 PM
I never knew...but I never needed it, so yeah XD
Report Abuse
XlegoX is not online. XlegoX
Joined: 16 Jun 2008
Total Posts: 14955
25 Mar 2009 08:24 PM
If you never needed it you must not have made anything very substantial...

It determines what a function is equal to as an expression when called EG:

function return_something(number)
return number * number
end

print(return_something(5)) --> prints 25
Report Abuse
level140roblox is not online. level140roblox
Joined: 08 Jun 2008
Total Posts: 9577
25 Mar 2009 08:24 PM
funtion lol(what)
return(what)
end


p = lol(workspace.Name)
print(p)
Report Abuse
level140roblox is not online. level140roblox
Joined: 08 Jun 2008
Total Posts: 9577
25 Mar 2009 08:25 PM
dangit x, everytime you post before me, and more in-depth...

Report Abuse
Jello715 is not online. Jello715
Top 100 Poster
Joined: 05 Feb 2008
Total Posts: 7491
25 Mar 2009 08:26 PM
I'm a bit confused...
Report Abuse
Raxz is not online. Raxz
Joined: 20 Dec 2008
Total Posts: 3432
25 Mar 2009 08:28 PM
return is sometimes needed to stop scripts from breaking. For example:

function onTouched(part)
if part.Parent == nil then return false end
local h = part.Parent:findFirstChild("Humanoid")
if h ~= nil then
-stuff
end
end

script.Parent.Touched:connect(onTouched)
Report Abuse
worldwaffle is not online. worldwaffle
Joined: 19 Feb 2008
Total Posts: 2073
25 Mar 2009 08:28 PM
or if you need it for a boolean value

function DoILikeStuff(object)
if(object ~= "") then
return false
else
return true
end
end

then you can put it in an "if" statement

if(DoILikeStuff("Words")) --that would return true, so would continue the code
print("This person likes something!")
else
print("This person is a goth")
end
Report Abuse
Blaboblox is not online. Blaboblox
Joined: 12 Sep 2008
Total Posts: 8945
25 Mar 2009 08:29 PM
Raxs its impossible for a brick without a parent to touch something.
Report Abuse
level140roblox is not online. level140roblox
Joined: 08 Jun 2008
Total Posts: 9577
25 Mar 2009 08:30 PM
Ima beat you x!

ok, so your returning something from a function, which giver you the ability to access that in things like printing, or any built in lua function.

function return_boolean(t_or_f)--self-explainatory. True or false.
return t_or_f --sets what it will return
end --...


if return_boolean(true) then
print("it is true")
end
Report Abuse
Raxz is not online. Raxz
Joined: 20 Dec 2008
Total Posts: 3432
25 Mar 2009 08:32 PM
Blab, you'd know why I use return false end in my onTouched scripts if you saw what happens when it gets hit by a bullet instead of a person.... XD
Report Abuse
Blaboblox is not online. Blaboblox
Joined: 12 Sep 2008
Total Posts: 8945
25 Mar 2009 08:33 PM
You need the humanoid part but otherwise like I said, anything that could touch it has a parent.
Report Abuse
level140roblox is not online. level140roblox
Joined: 08 Jun 2008
Total Posts: 9577
25 Mar 2009 08:33 PM
avoiding breaking scripts.

pcall(function() --your function)end)
Report Abuse
Raxz is not online. Raxz
Joined: 20 Dec 2008
Total Posts: 3432
25 Mar 2009 08:34 PM
Blab i'm serious. When you shoot a lava brick with a paintball gun it breaks -.-
Report Abuse
worldwaffle is not online. worldwaffle
Joined: 19 Feb 2008
Total Posts: 2073
25 Mar 2009 08:35 PM
my boolean return did that Level :P except it checked if a string was not nil and would return true or false. Just so you can use that in an "if()" and get something out of it :P
Report Abuse
Blaboblox is not online. Blaboblox
Joined: 12 Sep 2008
Total Posts: 8945
25 Mar 2009 08:36 PM
The lava? just do this:

function onTouched(hit)
hit:BreakJoints()
end
script.Parent.Touched:connect(onTouched)
Report Abuse
level140roblox is not online. level140roblox
Joined: 08 Jun 2008
Total Posts: 9577
25 Mar 2009 08:36 PM
protect calling it is more effecient and less error prone.
Report Abuse
Raxz is not online. Raxz
Joined: 20 Dec 2008
Total Posts: 3432
25 Mar 2009 08:38 PM
I don't mean JUST lava scripts. A paintball gun can break any dumb onTouched thing.

"Attempt to index field 'Parent' (a nil value)"
Report Abuse
level140roblox is not online. level140roblox
Joined: 08 Jun 2008
Total Posts: 9577
25 Mar 2009 08:39 PM
do this.

pcall(function() hit.Parent:BreakJoints() end)
Report Abuse
Blaboblox is not online. Blaboblox
Joined: 12 Sep 2008
Total Posts: 8945
25 Mar 2009 08:41 PM
but mine doesnt search for a parent. It just Breaks its joints. lol
Report Abuse
level140roblox is not online. level140roblox
Joined: 08 Jun 2008
Total Posts: 9577
25 Mar 2009 08:42 PM
but then you would lose your legs...
Report Abuse
zoo1997 is not online. zoo1997
Joined: 09 Mar 2009
Total Posts: 415
25 Mar 2009 08:44 PM
Jell,
maybe this will help.

The return statement is used to return values from a function. it can return 0, 1, or more values depending on your need. some people use it to exit a function so that subsequent code is not executed. if used, it must be the last line in a function or block.
Report Abuse
Blaboblox is not online. Blaboblox
Joined: 12 Sep 2008
Total Posts: 8945
25 Mar 2009 08:45 PM
if its a thin strip, yes. But if its like a patch of lava you'll lose legs, then torso, then die. D:
Report Abuse
level140roblox is not online. level140roblox
Joined: 08 Jun 2008
Total Posts: 9577
25 Mar 2009 08:45 PM
--continuing zoo's

Nothing will execute after the return.
Report Abuse
Jello715 is not online. Jello715
Top 100 Poster
Joined: 05 Feb 2008
Total Posts: 7491
25 Mar 2009 08:53 PM
Thanks for helping...but I'm still confused XD

Maybe I'm....OBSOLETE D:
Report Abuse
level140roblox is not online. level140roblox
Joined: 08 Jun 2008
Total Posts: 9577
25 Mar 2009 08:54 PM
Your returning a value from a function.

Simple.
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