Jello715
|
  |
 |
| 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
|
  |
| 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 |
|
|
|
| 25 Mar 2009 08:24 PM |
funtion lol(what) return(what) end
p = lol(workspace.Name) print(p) |
|
|
| Report Abuse |
|
|
|
| 25 Mar 2009 08:25 PM |
dangit x, everytime you post before me, and more in-depth...
|
|
|
| Report Abuse |
|
|
Jello715
|
  |
 |
| Joined: 05 Feb 2008 |
| Total Posts: 7491 |
|
| |
|
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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 25 Mar 2009 08:33 PM |
avoiding breaking scripts.
pcall(function() --your function)end) |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 25 Mar 2009 08:36 PM |
| protect calling it is more effecient and less error prone. |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 25 Mar 2009 08:39 PM |
do this.
pcall(function() hit.Parent:BreakJoints() end) |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 25 Mar 2009 08:42 PM |
| but then you would lose your legs... |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 25 Mar 2009 08:45 PM |
--continuing zoo's
Nothing will execute after the return. |
|
|
| Report Abuse |
|
|
Jello715
|
  |
 |
| 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 |
|
|
|
| 25 Mar 2009 08:54 PM |
Your returning a value from a function.
Simple. |
|
|
| Report Abuse |
|
|