|
| 01 Apr 2014 09:18 PM |
| Is there a way to stop a function? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
|
| 01 Apr 2014 09:20 PM |
| k thanks. I just never really use returns... *watching-you sign on return* |
|
|
| Report Abuse |
|
|
OzzyBlox
|
  |
| Joined: 04 Nov 2009 |
| Total Posts: 14166 |
|
| |
|
|
| 01 Apr 2014 09:24 PM |
| nop. I know how to script,I just don't use return. |
|
|
| Report Abuse |
|
|
OzzyBlox
|
  |
| Joined: 04 Nov 2009 |
| Total Posts: 14166 |
|
|
| 01 Apr 2014 09:24 PM |
| I know I was joking. Script:Destroy is not a good idea. |
|
|
| Report Abuse |
|
|
|
| 01 Apr 2014 09:25 PM |
| plus that face gave a dead giveaway that it wouldn't be good to do. Plus,all you got to do is read it and yea. Even a beginner with no scripting knowledge could know. |
|
|
| Report Abuse |
|
|
OzzyBlox
|
  |
| Joined: 04 Nov 2009 |
| Total Posts: 14166 |
|
|
| 01 Apr 2014 09:26 PM |
| Yes yes yes I know it was simply a joke. No need to explain how you know thats a bad idea. |
|
|
| Report Abuse |
|
|
| |
|
|
| 01 Apr 2014 09:28 PM |
| @Ozzy Ik i am einsteiin. (jk) |
|
|
| Report Abuse |
|
|
|
| 01 Apr 2014 09:30 PM |
| btw return didn't work. But,I used a if statement instead. |
|
|
| Report Abuse |
|
|
robotmega
|
  |
| Joined: 16 May 2009 |
| Total Posts: 14084 |
|
|
| 01 Apr 2014 09:54 PM |
| because you dont know how to use return |
|
|
| Report Abuse |
|
|
|
| 01 Apr 2014 09:55 PM |
if your trying to stop a function, its probably best to use if statements determining whether to go through with it. For example, if its a function that has no wait times, its not that big of a deal, just have the if statements determining the action.
However, if it is a loop, then I would prefer...
running = false
function run() if running == true then while running == true do wait() if running = false then break end end end end
This would be commonly used in a sprint script, such that when a player presses Shift, it would start running and turn running to true, and while he holds shift, he stays running, and when he releases shift, the running statement would become false again, therefore stopping the function.
I hope that made sense. |
|
|
| Report Abuse |
|
|
|
| 01 Apr 2014 10:56 PM |
You can return values too.
This would be a pointless function, but it shows what I mean.
repeat wait() until f()
function f() if game.Players.NumPlayers > 1 then return true end return false end
It basically pauses the script until at least two players are in the game. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 01 Apr 2014 10:59 PM |
| Put the function above the repeat loop. |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 01 Apr 2014 11:42 PM |
Yeah. return breaks a function, just like break breaks a loop.
EX;
script.Parent.Touched:connect(function(hit) if hit.Name = "DerpedOut" then return else print("Phew, DerpedOut didn't touch us (:") end end) |
|
|
| Report Abuse |
|
|