![]() ![]() ![]() You probably never need to worry about efficiency of these things and memory management so I think it all boils down to preference. This sort of stuff is what enabled me to create my own 2D GUI Physics Engine on Roblox with 729 active objects. But I’m a guy who hit the “60 upvalue limit” of Lua while heavily optimizing my Engines and APIs. You might say that these are really small changes and don’t really matter at all. ![]() You can also just run a function really fast and memory efficient without going through the trouble of adding the table to memory and manually garbage collecting it. Allowing you to make robust and easily flexible one with loops and interchanging events listening to all sorts of stuff. The only disadvantage that I can see is that the global variable might not have loaded and that’s it.Ī couple of advantages with _G is your code can run in the script that defined it. Wouldn’t, local deps = require(ModuleScript_For_TableOfFunctions) When you can’t just touch whatever you want from anywhere in the place code at a moment’s notice and have to add the require it makes you think for a second if you actually want to add a given dependency here. Makes you think about your code boundaries more carefully. That name gives you information on what that variable is for / what code is handling it. You have to name the Module that you put a particular global variable in. You know exactly what Modules depend on what other ones thanks to the requires and furthermore you know that the thing you’re depending on will actually be there when you use it-for free, you don’t need any awkward wait loops on _G variables. On the flipside, a ModuleScript:Įnforces a strict order of dependency. Literally the only advantage of using _G over a ModuleScript is that it’s slightly more terse thanks to not needing the require at the start of the script. Using a ModuleScript is basically strictly better than using _G. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |