Sorting a table of functions by index, but how?
I would like to make a table of functions. Functions have their indexes represented as a level id (e.g. 100, 101, 200, 201, 202...) to change some level properties (lighting, gravity ect)
So here is an example:
01 | local functionsTable = { } |
03 | functionsTable [ 100 ] = function () |
04 | print ( "This is a function number 100" ) |
07 | functionsTable [ 101 ] = function () |
08 | print ( "This is a function number 101" ) |
11 | functionsTable [ 201 ] = function () |
12 | print ( "This is a function number 201" ) |
You might ask, what's the problem? And a problem comes whenever a player connects to a server, and to apply all property changes in the past, my client script loops trough all of the functions in a table until it reaches current player's level. For example:
01 | local functionsTable = { } |
04 | functionsTable [ 100 ] = function () |
05 | print ( "This is a function number 100" ) |
08 | functionsTable [ 101 ] = function () |
09 | print ( "This is a function number 101" ) |
12 | functionsTable [ 201 ] = function () |
13 | print ( "This is a function number 201" ) |
16 | for i, v in pairs (functionsTable) do |
17 | print ( "Index " .. tostring (i)) |
18 | if i < = plrLevelId then |
21 | print ( "Skipped " .. tostring (i) .. " - done" ) |
Not only it skips a function that supposed to called in the order, but it called a function number 101, while function number 100 should be called first. What magic is this? How to go through all functions in a correct order that I assigned by index? Thank you in advance