1 | while wait( 5 ) do |
2 | local r = math.random( 1 , 10 ) |
3 | if r = = 1 then |
4 | randomstuff() |
5 | elseif r = = 2 then |
6 | otherrandomstuff() |
7 | end |
8 | end |
doing this much elseifs makes the code look bigger than it needs to be
how would i make this smaller?
1 | while wait( 5 ) do |
2 | local numberTable = 1 , 2 |
3 | local r = math.random( 1 , 10 ) |
4 | for i,v in pairs [ numberTable ] |
5 | if v = 1 then |
6 | randomstuff() |
7 | if v = 2 then |
8 | otherrandomstuff() |
01 | local functions = setmetatable ( { } , { __index = functions } ) |
02 |
03 | functions.first = function () |
04 | print ( 1 ) |
05 | end |
06 |
07 | functions.second = function () |
08 | print ( 2 ) |
09 | end |
10 |
11 | local random = Math.random( 0 , 2 ) |
12 | random = math.floor(random) |
13 |
14 | functions [ random ] () |