[AI] cRoot:Get():ForEachMob - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Plugins (https://forum.cuberite.org/forum-1.html) +--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html) +--- Thread: [AI] cRoot:Get():ForEachMob (/thread-1747.html) Pages:
1
2
|
RE: [AI] cRoot:Get():ForEachMob - wudles - 01-27-2015 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. RE: [AI] cRoot:Get():ForEachMob - xoft - 01-27-2015 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 |