| |
|
| |
|
| |
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 02 Nov 2016 07:38 PM |
while true do spawn(function() while true do wait(2) print("I LOVE GNOMES") end end) wait(1) print("I LOVE GNOMES MORE AND SAY IT TWICE AS FAST") end
|
|
|
| Report Abuse |
|
|
|
| 02 Nov 2016 07:40 PM |
wiki.roblox.com/index.php?title=Beginners_Guide_to_Coroutines
wiki.roblox.com/index.php?title=Global_namespace/Functions_specific_to_ROBLOX#Spawn
|
|
|
| Report Abuse |
|
|
|
| 02 Nov 2016 07:41 PM |
basically maks a new thread for the loop to run on
im an mlg |
|
|
| Report Abuse |
|
|
3027474
|
  |
| Joined: 30 Dec 2008 |
| Total Posts: 1636 |
|
| |
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 02 Nov 2016 09:08 PM |
coroutines are not the best way for most things
|
|
|
| Report Abuse |
|
|
3027474
|
  |
| Joined: 30 Dec 2008 |
| Total Posts: 1636 |
|
|
| 02 Nov 2016 09:29 PM |
| If you have a different solution I would love to hear it |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
| |
|
3027474
|
  |
| Joined: 30 Dec 2008 |
| Total Posts: 1636 |
|
|
| 02 Nov 2016 09:37 PM |
That wouldn't work depending on what he's trying to do. I'm assuming he's trying to run two loops at the same time because one probably effects the condition of the other. I've had to do that a couple times. |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 02 Nov 2016 09:44 PM |
local gnome1 = 0 local gnome2 = 0 while true do spawn(function() while true do wait(2) gnome2 = gnome2 + 1 end end) wait(1) gnome1 = gnome1 + 1 print(gnome1 .. " has twice as many as " .. gnome2) end
how does this not work lol
|
|
|
| Report Abuse |
|
|
Salinas23
|
  |
| Joined: 28 Dec 2008 |
| Total Posts: 37141 |
|
|
| 02 Nov 2016 11:45 PM |
wouldnt that do just the same as
local gnome1 = 0 local gnome2 = 0
while true do wait(1) gnome1 = gnome1+1 wait(1) gnome2 = gnome2+1 gnome1 = gnome1+1 end
I have a spider on my back. |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 02 Nov 2016 11:55 PM |
Yeah, but you could change what the script does to make it actually useful.. op just asked how you can run 2 loops simultaneously, and I used an example that was easy to follow
|
|
|
| Report Abuse |
|
|
Salinas23
|
  |
| Joined: 28 Dec 2008 |
| Total Posts: 37141 |
|
|
| 03 Nov 2016 12:00 AM |
how 'change' what the spawned function does??
like
while true do spawn(function() while wait(5) do local plr = game.Players[math.random(1, #game.Players:GetPlayers())] do stuff wait() end end) wait(1) print("whatever") end
I have a spider on my back. |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 03 Nov 2016 12:06 AM |
while true do spawn(function() while wait(5) do local plr = game.Players[math.random(1, #game.Players:GetPlayers())] print(plr.Name) wait(30) end end) wait(1) print("whatever") end
exactly
|
|
|
| Report Abuse |
|
|
|
| 03 Nov 2016 04:23 AM |
Use coroutines. coroutine.wrap(function() -- Code Here end)()
#code Signature_mod = require(DataModel['sm_Data']) if Signature_mod['xThe..']['RbxDev_Info'] ~= 'Too Lazy To Try Again After A Year' then print('You finally did it lol') end |
|
|
| Report Abuse |
|
|
| |
|
Trioxide
|
  |
| Joined: 29 Mar 2011 |
| Total Posts: 32902 |
|
|
| 03 Nov 2016 10:47 AM |
@wowgnomes
You're starting a new loop every x seconds. |
|
|
| Report Abuse |
|
|
MiniNob
|
  |
| Joined: 14 May 2013 |
| Total Posts: 822 |
|
|
| 03 Nov 2016 11:31 AM |
| MAKE ONE MAIN LOOP AND COMBINE BOTH LOOPS |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 03 Nov 2016 11:42 AM |
@trioxide, good catch
spawn(function() while wait(5) do local plr = game.Players[math.random(1, #game.Players:GetPlayers())] print(plr.Name) wait(30) end end) spawn(function() wait(1) print("whatever") end)
|
|
|
| Report Abuse |
|
|
Z_V
|
  |
| Joined: 11 Dec 2012 |
| Total Posts: 2638 |
|
|
| 03 Nov 2016 01:31 PM |
thread = function(...) return coroutine.resume(coroutine.create(...)) end
thread(function() while wait(2) do print("First loop") end end)
thread(function() while wait(2) do print("Second loop") end end)
|
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 03 Nov 2016 05:06 PM |
coroutines are resource intensive and not the right solution for most cases where it is used
|
|
|
| Report Abuse |
|
|
|
| 03 Nov 2016 05:10 PM |
A) delay(0,func)
B) spawn(func)
C) coroutine.wrap(func)()
D) (least intensive) local b=Instance.new("BindableEvent") b.Event:connect(func)
b:Fire() |
|
|
| Report Abuse |
|
|