Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Corotine? Please help me...

Asked by 9 years ago

So what I've been doing is this, but it seams stupid to put a function inside a function, is there a way I can combine the name with the corotine with being able to call the function at any time I want to?

local message=function(text)
coroutine.resume(coroutine.create(function()
guiFrame.Msg.Text=text
wait(.15)
guiFrame.Msg.Text=''
end))
end
0
Anyone? Please? kingmatt2 15 — 9y

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago
function funcName(params)
    --code
end

Is just syntactic sugar for.

funcName = function(params)
    --code
end

There isn't a way to just bind a coroutine to a re-usable function that I know of, but if you want to pass in the parameter to the coroutine function, do this:

local message=function(text)
    coroutine.resume(coroutine.create(function(txt) --parameter in inner function
        guiFrame.Msg.Text = txt --parameter in inner function
        wait(.15)
        guiFrame.Msg.Text = ""
    end), text) --parameter *from* outer function. Note the parentheses placement.
end
0
spawn(func) is much shorter and clearer BlueTaslem 18071 — 9y
0
`spawn` doesn't spawn the thread until the next yield in the current thread, and you *can't* pass in parameters to the Spawned function directly, as here. adark 5487 — 9y
Ad

Answer this question