![]() ![]() You can use 'or' to avoid this as shown below. But if you click on that script again later and back off it will save and overwrite your current data. Often times you need to initialize your tables at the top of your scripts. Get into a habit of using a namespace for your scripts instead - see below.Īvoid overwriting your variables accidentally For instance, all it takes is accidentally writing to _G and suddenly all of your scripts which send commands to the game are broken. The very thing which makes _G useful (being able to reference elements if you don't know their name before hand) is what makes it dangerous, as it can be easy to overwrite things you shouldn't and leave yourself in a broken state. It's not only good practice to use local variables where possible, but you should avoid referencing the global table, _G. For instance, if you are going to cycle through a large table and cecho items from within it, adding local cecho = cecho above the loop can improve performance.this means you can increase the speed of intensive processes just by making functions and variables local before using them.local variables are inherently faster in Lua, as they exist in the virtual machine registers and are a simple index lookup to access, whereas globals reside in a table and are therefore a hash lookup.self.mc is a bit much to type and remember, but if you first do local console = self.mc then it's obvious you're referring to a console where you use it in future.You can make the code easier to both read and write.You are probably not the first person to use "tbl" for a temporary table name. Making things local keeps them from colliding with variables in use by other package developers.There are three main reasons for doing so: msg cecho ( transformed_msg ) end - better function myEcho ( msg ) local transformed_msg = "(Highlighter)". bad function myEcho ( msg ) transformed_msg = "(Highlighter)". If you will need to access it repeatedly in your script, make it local first.Īlways be asking yourself, "Could I be using a local instead?" If a variable is only needed for the duration of a function, alias, or trigger, then make it a local every time. You should really be using local variables wherever you can. Optimizations and items specific to Mudlet's triggers, aliases, API, etc.keeping your UI looking it best in as many situations as possible.Potential exceptions will be noted with their entries. ![]()
0 Comments
Leave a Reply. |