[AI] cRoot:Get():ForEachMob
#11
Ok. Lua tables are just associative arrays that you can nest. This works. The idea that all variables are global is kind of scary in Lua. I'm prefixing all my non-local variables with my plugin name, just to be sure.
Reply
Thanks given by:
#12
The variables are global by default, but each plugin executes in its own sandbox, so you don't need to prefix by plugin name, that's kinda counter-productive. You might want to use file-local variables, though - if you declare a variable as "local" on the file level (without any enclosing function), the variable will be accessible to all the file's functions, but no-where else. This is useful for self-contained modules that have some form of a global state, so that they don't leak that state out.

Of course, getting into the habit of using as much "local" as possible is always a good thing. I think when the Core plugin was developed this idea hasn't been rooted too strong yet, so there's a lot of instances in Core that could use localising Smile
Reply
Thanks given by:




Users browsing this thread: 3 Guest(s)