I’ve been working on a module that can help clean up the way longer if statements look.
It can check and compare any type of value given to it (strings, numbers, booleans, Vector3s, parts, etc.) and run any function attached.
You can place it wherever you like, or even clone it, but I like to keep it in ReplicatedFirst because it’s a nice universal spot where any script can require it.
I’ve decided I want to make a fan change between power levels when you click on the corresponding buttons using my switch statement.
Here's what it looks like.
It has 6 buttons: four power levels, and two buttons for power on/off. 3 of these buttons have nothing to do, so they’ll share functions with other buttons, provided they come next in the list.
3 buttons don’t have functions assigned, but their names do appear in the case list, so the switch statement will find them, and then iterate down until it reaches the next viable function.
“On” and “Medium” both have nothing in them, but they do come before another case that does. The switch statement will run the first case it finds after both of the blanks.
Let’s watch it work:
Here’s a link to the module, with the fan included!
Let me know what you think! If you can think of any way to make the module more efficient, I’d really appreciate any advice!