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
|
  |
| 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
|
  |
| Joined: 09 Nov 2012 |
| Total Posts: 328 |
|
| |
|
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
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
| |
|
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
|
  |
| 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
|
  |
| Joined: 09 Nov 2012 |
| Total Posts: 328 |
|
| |
|
transIate
|
  |
| Joined: 20 Jun 2013 |
| Total Posts: 2699 |
|
| |
|
|
| 11 Apr 2014 07:45 PM |
| I think break is only for loops |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 11 Apr 2014 07:46 PM |
| Yeah, he probably meant return |
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 29 Jan 2012 |
| Total Posts: 25287 |
|
| |
|
|
| 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 |
|
|
| |
|
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 |
|
|
|
| 11 Apr 2014 08:28 PM |
agent was one of the first 100 posters on roblox.
#nerdsunited |
|
|
| Report Abuse |
|
|
|
| 11 Apr 2014 08:29 PM |
| Top#Poster is a broken feature |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 11 Apr 2014 08:30 PM |
| No, the disconnect method still works |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 11 Apr 2014 08:37 PM |
| What did you just call me ... ? |
|
|
| Report Abuse |
|
|
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 |
|
|