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 » Scripters
Home Search
 

Re: Is there a way..

Previous Thread :: Next Thread 
Bassics is not online. 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
EchoReaper is not online. EchoReaper
Joined: 14 Oct 2008
Total Posts: 4323
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 is not online. 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 is not online. 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 is not online. 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 is not online. bohdan77
Joined: 10 Aug 2008
Total Posts: 7944
11 Apr 2014 06:04 PM
coroutines?
Report Abuse
morash is not online. 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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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