Alternative solution for Lots of Conditions?

I want to simplify the progress of adding If’s for each variables so it won’t take much time to use it.

game.ReplicatedStorage.ShakeCamera.OnClientEvent:Connect(function(magnitude,roughness,fadeintime,fadeouttime,posinflu,rotinflu)
	local shake = camShake:ShakeOnce(magnitude,roughness,fadeintime,fadeouttime,posinflu,rotinflu)
end)

as you can see there’s a lot of variables in there.
i tried something like this :

m = magnitude or 1

but rather than getting the results i want, the variable just went crazy and chaotic.
for example the magnitude value becomes PosInflu value.
i also need this kind of method for complex AI that has lots of condition.

1 Like

You could do this to shorten your code:

game.ReplicatedStorage.ShakeCamera.OnClientEvent:Connect(function(…)
local shake = camShake:ShakeOnce(…)
end)

1 Like

For the sake of understanding what this: it’s a Variadic Function. The linked article provides information on what it is and how to use it. The specific technique (iirc) adopted in this code sample is argument forwarding. You take what you get from a client-received message and forward that to a function.

2 Likes