Thursday, April 19, 2012

[SC2] UCA0021

uca0021 are the little bots that fly around when building structures, but why is the script of TypeClass = UCA0103?|||GPG didn't bother to change it lol just left over code.|||Doesn't hurt anything, just looks confusing. For per-unit scripts, the game doesn't look at the name of the class, it looks at the contents of TypeClass.
So you can technically have a class that's named something totally different than the file, and you can technically even have a bunch of unit scripts that all use the same class name (which happened with some Cybran projectiles in FA). It's bad practice, but it still works.
This only applies to per-unit scripts with TypeClass, of course, and if you tried to 'rename' the Unit class in Unit.lua, your changes would be ignored because all of the other lua scripts that import /lua/sim/Unit.lua.Unit would see the old version referenced by 'Unit'.

Edit: The reason different scripts can use the same variable names is because every import()ed script is doscripted into its own global environment within __modules, and has a custom metatable that redirects all failed global variable accesses within that environment to the lua state's global environment.

No comments:

Post a Comment