How to put a function parameter inside a module function?

I have a function in my tools, probably the worst way to go by it but it works. It has 1 parameter and that is a string.

You can see here in this code that I try putting the parameters in for it, however, it has red underlines.

function module.Action(playanimation(animparam : string))
	
end

image
image
image

*Note that this is only a fraction of another function that uses this parameter.

I searched on the devforum that it is possible to put a function within a parameter, but it hasn’t helped at all.

What am I doing wrong here? Should I try a completely different approach to this?

Do this

local function callOtherFunction(func, …)
    func(…)
end

Basically you can send a function so that the other function can call it, but you can’t tell the other function exactly what the parameters are. You will have to pass them inside the function.

The … in this example is valid code that just tells the outer function to pass any extra parameters through to the inner function.

But you could give dedicated parameters instead in the outer function you just pass through.

If you need more control, you can technically split up the … as you need, but generally you’re probably better off redesigning if it comes to that.

2 Likes

I’m gonna see if this works, thank you :stuck_out_tongue:

but generally you’re probably better off redesigning if it comes to that.

I do agree, I have worked around a similar issue before by putting the function in the modulescript. Thanks!

The technical name for this is a variadic function!

You can read more about its syntax here.

2 Likes

Ooh! Thank you for this information, I will take note.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.