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: How to stop a function?

Previous Thread :: Next Thread 
pivot513 is not online. pivot513
Joined: 09 Nov 2012
Total Posts: 328
11 Apr 2014 04:37 PM
Is there any way to enable and disable functions to happen? For example

script.Parent.Touched:connect(onTouch)

Is it possible for that to be disabled, for example that is only activated for a certain amount of time?
Report Abuse
devRaver is not online. devRaver
Joined: 08 Apr 2013
Total Posts: 531
11 Apr 2014 04:42 PM
Touched = script.Parent.Touched:connect(onTouch)
Touched:disconnect()

I think that's it?
Report Abuse
pivot513 is not online. pivot513
Joined: 09 Nov 2012
Total Posts: 328
11 Apr 2014 05:47 PM
OKay, thanks.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Apr 2014 05:58 PM
That's disconnecting an event, not stopping a function
Report Abuse
RoflBread is not online. RoflBread
Joined: 18 Jun 2009
Total Posts: 3803
11 Apr 2014 06:06 PM
It's what OP asked for
Report Abuse
pivot513 is not online. pivot513
Joined: 09 Nov 2012
Total Posts: 328
11 Apr 2014 07:15 PM
Um.... Yeah. I tried it and it didn't work.
Report Abuse
BladeXE is not online. BladeXE
Joined: 22 Dec 2012
Total Posts: 3857
11 Apr 2014 07:19 PM
if --code then return end
exits the function if --code is true
Report Abuse
pivot513 is not online. pivot513
Joined: 09 Nov 2012
Total Posts: 328
11 Apr 2014 07:19 PM
Oh I see, thanks.
Report Abuse
transIate is not online. transIate
Joined: 20 Jun 2013
Total Posts: 2699
11 Apr 2014 07:20 PM
if
--code
then break end;
Report Abuse
KiwiTronik is not online. KiwiTronik
Joined: 18 Feb 2010
Total Posts: 3221
11 Apr 2014 07:45 PM
I think break is only for loops
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Apr 2014 07:46 PM
Yeah, he probably meant return
Report Abuse
transIate is not online. transIate
Joined: 20 Jun 2013
Total Posts: 2699
11 Apr 2014 07:53 PM
ya my fault I just remembered after I posted
Report Abuse
Azureous is not online. Azureous
Joined: 29 Jan 2012
Total Posts: 25287
11 Apr 2014 08:10 PM
else return end
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
11 Apr 2014 08:20 PM
devReaver was correct.
Your delay that you want needs to go between those two statements, OP.



Touched = script.Parent.Touched:connect(onTouch)
wait(60)
Touched:disconnect()



The above will listen for touching for 60 seconds, and then disable itself. However, any function that is running as a result of the Touched event firing will NOT disable (this means if you have any loops in your onTouch function, this may not work as expected). To get around this, you can have a variable stored to tell whether the script is currently listening:



local listening = true
Touched = script.Parent.Touched:connect(onTouch)
wait(60)
Touched:disconnect()
listening = false



And inside any loops you have in onTouch, you can have something like this:


if not listening then return end


And that would effectively disable any loops you may have running.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
11 Apr 2014 08:21 PM
devRaver*

Apologies.
Report Abuse
BladeXE is not online. BladeXE
Joined: 22 Dec 2012
Total Posts: 3857
11 Apr 2014 08:28 PM
Wait
Azur.Totalposts>Agent.Totalposts
Agent is top 100
Azur isn't
dacrap?
Report Abuse
VerifiedName is not online. VerifiedName
Joined: 26 Jul 2009
Total Posts: 4534
11 Apr 2014 08:28 PM
agent was one of the first 100 posters on roblox.

#nerdsunited
Report Abuse
lightwavestd is not online. lightwavestd
Joined: 02 Apr 2013
Total Posts: 1330
11 Apr 2014 08:29 PM
Top#Poster is a broken feature
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Apr 2014 08:30 PM
No, the disconnect method still works
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
11 Apr 2014 08:33 PM
t = script.Parent.Touched:connect(function()
while wait(1) do
print "Touch loop!"
end
end)

wait(5)

t:disconnect()
print "Disconnected"





Still loops after the disconnect method is called.
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
11 Apr 2014 08:34 PM
Of course, it's outside the loop. A while loop will go on forever, so it will never reach the disconnect anyway.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
11 Apr 2014 08:36 PM
It does reach the disconnect method because the loop is inside a separate thread.
I'm showing that even if the event is disconnected, any loops still run (in fact, the separate threads all still run, unless they're reached the end, and they 'die' and are GC'd).
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
11 Apr 2014 08:37 PM
Why'd I even try correcting you. You invented the cow!
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
11 Apr 2014 08:37 PM
What did you just call me ... ?
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
11 Apr 2014 08:39 PM
The inventor of the cow:
http://web.roblox.com/Forum/ShowPost.aspx?PostID=127605920
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