Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Corotine? Please help me...

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

1 comment

0

Anyone? Please?

1 answer

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

2 comments

0

spawn(func) is much shorter and clearer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.