|
| 29 Nov 2015 03:12 PM |
length = 1
wait(1)
start = coroutine.create(function() for i = 9, 0, -1 do for j = 59, 0, -1 do if j > 9 then script.Parent.Text = i .. ":" .. j else script.Parent.Text = i .. ":0" .. j end wait(length) end end for i = 1, 2 do script.Parent.Font = "SourceSansBold" wait(0.5) script.Parent.Font = "SourceSans" wait(0.5) end end)
coroutine.resume(start)
script.Parent.Parent.SpeedTimeGui.MouseButton1Down:connect(function() length = 0.05 coroutine.yield(start) coroutine.resume(start) end)
script.Parent.Parent.SpeedTimeGui.MouseButton1Up:connect(function() length = 1 coroutine.yield(start) coroutine.resume(start) end)
All of that works until I stop clicking the button. The time starts going up at increments of like 3 and gets worse if I keep clicking
This is advertising. |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
| 03 Dec 2015 10:09 PM |
Never understood coroutines, cant help here :/ But what is happening is that a function is being called and connected multiple times, everytime you click it, it connects a function, and so when you click it again, it keeps the previous function and so over and over. But like I said, if that isnt it then blame it in my little knowledge on coroutines. |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2015 06:33 PM |
I would expect yielding the coroutine to do what yield actually means, and resuming it would do what resume actually means.
This is advertising. |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2015 07:41 PM |
| Looked a bit more into it, resuming it re runs the code I believe. Thats how it works, but it COroutines with the previous one, stacking the effect. |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2015 07:55 PM |
I was thinking about if that was the cause. How would I go about preventing that?
This is advertising. |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2015 09:43 PM |
| Ending a function, disconnecting it, breaking it. Any of those should work. |
|
|
| Report Abuse |
|
|
hkep
|
  |
| Joined: 19 Jul 2014 |
| Total Posts: 550 |
|
|
| 04 Dec 2015 09:49 PM |
add this
local function Start(Break)
-- check if break[1] == true
end;
local Current = {false};
coroutine.wrap(Start)(Current);
onDown function() Current[1] = true Current = {false} coroutine.wrap(Start)(Current) end |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2015 09:57 PM |
^ That would call an error most likely, given as you are trying to wrap a coroutine with 2 arguments, or it could still be I dont understand coroutines. |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2015 09:58 PM |
| It's the latter. He is wrapping the function, and then calling the wrapped function. |
|
|
| Report Abuse |
|
|
|
| 04 Dec 2015 09:59 PM |
And just a shot in the dark here, but is this being used in a time related function? As in a clock? Given you can see "script.Parent.Text = i .. ":" .. j else script.Parent.Text = i .. ":0" .. j" Which looks like its trying to format it in a clock-like manner. |
|
|
| Report Abuse |
|
|
|
| 05 Dec 2015 08:37 AM |
yes, when I hold down left click on a button I want the timer to speed up but when I release I want it to go back to normal
This is advertising. |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
|
| 05 Dec 2015 07:49 PM |
| When the mouse button is pressed, connect a function that depends on a variable that's changed when the mouse button is released. That's how automatic guns work. |
|
|
| Report Abuse |
|
|
|
| 05 Dec 2015 07:50 PM |
I'll try that
This is advertising. |
|
|
| Report Abuse |
|
|
|
| 05 Dec 2015 09:02 PM |
how would I change the length of time that the loop waits without iterating through the whole script again each time the mouse is brought down/released?
This is advertising. |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 05 Dec 2015 09:17 PM |
length = 1
wait(1)
start = coroutine.create(function() for i = 9, 0, -1 do for j = 59, 0, -1 do if j > 9 then script.Parent.Text = i .. ":" .. j else script.Parent.Text = i .. ":0" .. j end wait(length) end end for i = 1, 2 do script.Parent.Font = "SourceSansBold" wait(0.5) script.Parent.Font = "SourceSans" wait(0.5) end end)
coroutine.resume(start)
script.Parent.Parent.SpeedTimeGui.MouseButton1Down:connect(function() length = 0.05 end)
script.Parent.Parent.SpeedTimeGui.MouseButton1Up:connect(function() length = 1 end) |
|
|
| Report Abuse |
|
|
|
| 05 Dec 2015 09:19 PM |
^ you wish
This is advertising. |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 05 Dec 2015 09:22 PM |
What's wrong with that? It seems to do as you describe.
wait internally calls yield and schedules the thread to resume at a later time. What you are doing is resuming the thread early when you pick the button, which runs through the body again and wait() schedules the task an additional time. This creates the stacking effect thread is scheduled to resume multiple times within the stack. |
|
|
| Report Abuse |
|
|