[Tutorial] Submodes |
Bolodefchoco « Sénateur » 1527706260000
| 5 | ||
Several EN friends have asked me how to make a submode system just like #grounds, so this is the thread. I'll make it the way I think the performance wins, but there are many other ways (and even easier, but with a bad performance / flexibility) (imo) I find interesting an initial table with the module info, as its name, the author, version, etc. Code Lua 1 2 3 local module = { Now we'll create the table mode that is fundamental in the system. It'll be the main table for every single module in your script! For now, we'll just create it. Code Lua 1 local mode = {} Now we'll create a new event that is going to be triggered in every module change. Code Lua 1 2 3 4 5 eventOnModeChange = function()
Now that we've our event finished, we'll make another function to get the specified module and trigger it if the module is valid. A getter. Code Lua 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 -- You can also make a timer to avoid mode change several Now one of the most important steps: defining the character that specifies the module name in the name of the room. Code Lua 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 -- We'll create a table to say the character and the function that handles the value post-character.
Now you can make your modules. Code Lua 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 -- Use functions in the format NAME = function(parameters) Be patient, we are close! Now one of the most important and fundamental parts of the system: the initializer function. Code Lua 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 -- We'll make a table with the names of all the official events
Tada! It's done! Dernière modification le 1557407940000 |
1 | ||
Great tutorial, thank you! |