• Global vars
    4 replies, posted
What's the taboo with using global variables and or functions in lua? Everyone always says that you need to define your variables as local or else they will conflict with other addons and what not, correct me if I'm wrong, but lua is one of the only languages I've seen where you actual define a variable or function as local. How could code in separate files conflict with each other without calling include()?? I've been wondering this for awhile now...
Including a file means all of it's global variables will be put into _G. If multiple addons have the same global variable names, they will conflict and overwrite each other. You should only try to have one global namespace table per addon and keep all of the functions you need cross-file in there.
[QUOTE=code_gs;51989796]Including a file means all of it's global variables will be put into _G. If multiple addons have the same global variable names, they will conflict and overwrite each other. You should only try to have one global namespace table per addon and keep all of the functions you need cross-file in there.[/QUOTE] Okay, that makes sense. So if you don't use include() then there isn't any reason to make all of your variables and functions local other than for consistency?
[QUOTE=MrRalgoman;51989823]Okay, that makes sense. So if you don't use include() then there isn't any reason to make all of your variables and functions local other than for consistency?[/QUOTE] Why would you not include a file? Just to note, autoran files are still technically included files, they're just done automatically
[QUOTE=code_gs;51989854]Why would you not include a file? Just to note, autoran files are still technically included files, they're just done automatically[/QUOTE] Oh, okay. I didn't know that either. That makes a lot more sense, thanks for the answers.
Sorry, you need to Log In to post a reply to this thread.