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

I'm confused of how a variable can be a function?

Asked by 4 years ago
Edited 4 years ago

So take a good look at the script below here:

local variable = function count()
    for i = 1, 10 do
        print("Counting up from "..i)
    end
end

I am confused of how it is put together. It reminds me of a coroutine though but does that mean I can do this?

variable() 

Or does it just return like a normal function?

local variable = function count()
    for i = 1, 10 do
        print("Counting up from "..i)
    end
    return 10
end

print(variable) --> 10??

Can it even be used for a coroutine too?

coroutine.resume(coroutine.create(variable)) -- my way of making coroutines

I have no idea what it is and I have been seeing it in scripts recently and I'm sure that it just returns like a normal function.

Answer this question