I’m trying to make boss fight, but has little bug that boss still attacks after it dies.
I could try few methods but I don’t think these are good practice.
First, I added “if” to check if it’s dead.
local function attack()
wait(1)
if not dead then print("attack") end
wait(1)
if not dead then print("attack") end
wait(0.5)
if not dead then print("i throw projectile") end
end
this kinda works but code looks really messy.
Second, I tried coroutine.close to stop it.
local dead = false
local currentCo = nil
coroutine.wrap(function()
wait(1.5)
dead = true
print("i died")
coroutine.close(currentCo)
end)()
local function attack()
wait(1)
print("attack")
wait(1)
print("attack")
wait(0.5)
print("i throw projectile")
end
currentCo = coroutine.create(function()
attack()
end)
coroutine.resume(currentCo)
also this one works too, but it printed “cannot resume dead coroutine” at last.
And I don’t even think this is how coroutines are used for, just to stop thread.
Then, what should I use for this problem?