Bassics
|
  |
| Joined: 24 Apr 2012 |
| Total Posts: 415 |
|
|
| 11 Apr 2014 03:30 PM |
..to disable a function like you would a Script object?
Say I made a script with an infinite while loop. I could just disable the script to stop everything.
Is there a way for me to create a function, call it, and disable the function without having to create a bunch of breaks within the function? |
|
|
| Report Abuse |
|
|
|
| 11 Apr 2014 03:32 PM |
Straight from your profile: "I am a programmer. "
Wouldn't a programmer know the solution for this? On top of that, try Scripting Helpers instead. |
|
|
| Report Abuse |
|
|
Bassics
|
  |
| Joined: 24 Apr 2012 |
| Total Posts: 415 |
|
|
| 11 Apr 2014 03:44 PM |
@Echo
I can't find any documentation of what exactly I was looking for. I turned to here wondering if I could get some input from fellow programmers.
I could do something like this:
----
local Running = true A = function() while Running do -- wait() end end
A() Running = false
----
Although, I was looking for a way to stop the thread of the function immediately without using breaks like that. |
|
|
| Report Abuse |
|
|
Maroy
|
  |
| Joined: 15 Mar 2009 |
| Total Posts: 59 |
|
|
| 11 Apr 2014 03:50 PM |
| As far as I know, there is no "right" way to do this, since Lua (like most programming languages) was designed to execute synchronously without external pausing. There may be a trick involving coroutines and yield(), but you'll need to put checks in your function code either way. |
|
|
| Report Abuse |
|
|
MettaurSp
|
  |
| Joined: 20 Mar 2010 |
| Total Posts: 3179 |
|
|
| 11 Apr 2014 04:49 PM |
| You can also code how to do so into a function using a method such as callbacks. |
|
|
| Report Abuse |
|
|
bohdan77
|
  |
| Joined: 10 Aug 2008 |
| Total Posts: 7944 |
|
| |
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 11 Apr 2014 07:31 PM |
| If the loop is called by an event, then you use another event to set a Boolean and check in the loop for this Boolean and set it to the original thing and just insert a break. Try scripting helpers next time. |
|
|
| Report Abuse |
|
|
|
| 11 Apr 2014 08:18 PM |
...This is actually pretty simple.
_G.AllowSayToRun = true
function Say(msg) if _G.AllowSayToRun == true then print(msg) end end
Change _G.AllowSayToRun to false from any script, and that function is pretty much disabled -_-
Feel free to stop while loops too
_G.AllowLoopToRun = true
while wait() do if _G.AllowLoopToRun == true then print("stuff") end end |
|
|
| Report Abuse |
|
|
Devoi
|
  |
| Joined: 09 Jun 2013 |
| Total Posts: 5387 |
|
|
| 11 Apr 2014 09:12 PM |
while boolean do end
while true do if not boolean then break end end
function f() if not boolean then return end end
while wait() do f() end |
|
|
| Report Abuse |
|
|
lolb3
|
  |
| Joined: 16 Jan 2010 |
| Total Posts: 2268 |
|
|
| 12 Apr 2014 11:41 AM |
local bool = true
coroutine.wrap(function() while bool do print("l") end end)()
wait(4) bool = false |
|
|
| Report Abuse |
|
|