Answered by
8 years ago Edited 8 years ago
Referring to your "elseif" format
In Lua, there is no switch statement like other programming languages, so the whole "elseif" thing is the best way to do it. While there are other ways like using tables to connect functions together, it might just make it more complicated:
05 | caseof = function (self, code) |
07 | if (self.casevar) then |
08 | f = code [ self.casevar ] or code.default |
10 | f = code.missing or code.default |
13 | if type (f) = = "function" then |
14 | return f(self.casevar,self) |
16 | error ( "case " .. tostring (self.casevar).. " not a function" ) |
25 | function onMouseButton 1 Click() |
26 | switch(number):caseof { |
27 | [ 1 ] = function () return "It's 1" end , |
28 | [ 2 ] = function () return "It is 2" end , |
29 | [ 3 ] = function () return "dudeboy, it's 3" end |
33 | script.Parent.MouseButton 1 Click:connect(onMouseButton 1 Click) |