Hello people of DevForum! I would like to make a few things clear before I showcase my module:
- I’m aware this has been made many times before
- I did not make this to be used practically, but for fun
- You can use this wherever you want, anyone could have made this
Switch Statements Module
Module Code
local module = {}
function module.Switch(arg: any, cases: {})
for caseval, func in cases do
if arg ~= caseval then continue end
func()
end
end
return module
To initiate a Switch statement, you must give two arguments. The first argument is the variable to check, and the second argument is a key-value dictionary. Each key must be the Case you are checking for, and the Value a function().
Example of how to use the module:
for Counter = 1, 3 do
module.Switch(Counter, {
[1] = function()
print("It's one!")
end,
[2] = function()
print("Wow, it's two?")
end,
[3] = function()
print("Would you know it! It's THREE!")
end,
["Hello World"] = function()
warn("It's not meant to be a string!!!")
end,
})
end
Keep in mind, this is all a bit of fun! ![]()