I am pretty new to using coroutines in lua, so I am having trouble getting them to work the way that I want them to.
Essentially what I am trying to do is to run this function asynchronously
function UpdateCoroutine(control, name, value, init, final, rate, time)
print("test")
local tick = 0
print(tick)
while ( tick < time ) do
print(tick)
value = init + (final - init)*(1 - math.exp(-1 * rate * tick / time)) / (1 - math.exp(-1 * rate))
tick += 1
coroutine.yield()
end
value = final
print("ending")
Threads[name] = nil
end
I create the thread here.
Threads.SG = coroutine.create(UpdateCoroutine(Reactor.Controls.ToggleSG, "SG", Reactor.Status.SG, 0, 100, 5, 50))
The debug print statement before this line runs, but the print statement after this line does not run, so something weird is happening here.
Then, I am running the thread with
local function UpdateValues()
for _, thread in Threads do
print("RUNNING THREAD")
coroutine.resume(thread())
end
end
The print statement here never happens, so this isn't running. It is also worth noting that this is the ONLY place that I use coroutine.resume.
The first print statement in UpdateCoroutines DOES get printed. Since my UpdateValues function isn't running, why is my coroutine running? It's also worth noting that it only runs one time, when UpdateValues gets called every 0.1 seconds.
Thanks for the help : )
** You are now Level 8! **