If you want to do something like that, it would probably make sense to investigate into the route of object oriented programming. Currently, you have a class (your gun) which has a ton of generic attributes (pellets, damage, whatever), and are looking to use a function for that gun, or otherwise āobjectā, which would become a method.
There are tons of guides online to this concept, so Iāll link whatever ones I find online here - this doesnāt mean theyāre necessarily good, theyāre just the first to come up.
To clarify, Iām going to have a module script with all the different gun types(burst, shotgun, projectile,. etc.) and Iām going to have generic functions attached to those that I can just pull out of the dictonary. However, then Iāll pull more specific stats like damage and firerate out of a different dictonary and pass them into the generic function.
Finally, Iāll do something like self.fireFunction = genericFunction(stats) in the gun object but I canāt do that; thatās why I asked the question lol.
A function is automatically called if you put something after it (most commonly parenthesis) that behavior cannot change. But you can call a function within another function
local function funcx(x)
return x
end
local function funcy(y)
return y
end
local function call_funcs()
local x = funcx
local y = funcy
local value_x = x(2)
local value_y = y(5)
print(value_x + value_y)
end
call_funcs() --> 7
So, youāre saying, if I make a lambda function with the generic function and stats passed in, itāll work. Ok, wow, canāt believe I didnāt think of that lol, thank you so much.