Welcome Guest ( Log In / Register ) |
Quick Lists Top RatedTutorials Living World Map G… Ultimate beginner'… Arrow scaling bug… Raising Heroes max… Creating an asset.… Proper Fire Arrow… Simple Structure B… Making a simple Ma… Quick and easy sno… Making patrols nea… Mods The Dwarf Holds The Peloponnesian… RJ - RotWK The Elven Alliance… Helm's Deep Last H… The Elven Alliance Special Extended E… Kings of the West… RC Mod The Wars of Arda Downloads BFME1 1.06 Widescr… Enhanced W3D Impor… Fudge's Map Pack LotR/BfME HD Logos Osgiliath Shellmap Crystals Of Ancien… 2v1 Wold The forests of Dru… Converted BFME2 an… ROTWK animations f… |
|||||||||||||||||||||||||||||||||
Register and log in to move these advertisements down Advanced LUA: Helper Functions
This page deals with storing unchanging data in a function... things like subobject lists. Unfortunately, you can't declare global unchanging variables in scripts.lua. This means that you can't just store all the subobject lists (for the two helper functions on the previous pages) for a unit at the top of the file where they can be easily accessed. This normally isn't a problem, because such lists aren't used more than once in most cases - we just stick them in the top of the function as before. However, what if you have a very complex bit of lua where you repeatedly want to access the same list in different spaces? Say 2 OnCreate scripts that are only slightly different? Or, you anticipate changing the model's subobjects in the future. If you could change one master list instead of all of them, it would be much easier. This next function can sit at the top of the scripts.lua and just contains data. It can be used any time you need the data it contains. Unlike the other two functions I've written in the article, it actually outputs a value (or in this case, several values - a list).
I can use this in my Orc code too...
Note how the parameter of "helmets" corresponds to the "helmets" section in the function. That lets it fetch the right subobject list. You would need to write a function of this type for every unit, something like:
With the appropriate lists of subobjects and categories written in. This concludes the tutorial. I hope someone finds it useful - though it may be difficult to grasp the concepts of functions without some basic programming experience, and difficult to write them without more specific lua programming basics. CommentsDisplay order: Newest first Nertea (Team Chamber Member) - Tuesday December 22, 2009 - 9:25 lua tables aren't really pure arrays because of their interesting key/record system. I'm not really a programmer, but my experience with actual programming languages has shown that lua tables don't behave the same way, so I guess it's ok for them to call them something else. Kinda like python's lists really. Bart (Administrator) - Friday December 18, 2009 - 4:47 Nice tutorial. I wonder why LUA calls arrays tables though. Nertea (Team Chamber Member) - Saturday November 21, 2009 - 12:42 Glad it's a bit helpful. I do want to know if anybody uses this, and with what degree of success, partially for interest's sake and partially to see if it's worth writing up stuff about other lua script tricks that I've developed/am developing. Rob38 (Team Chamber Member) - Thursday November 19, 2009 - 17:29 Interesting. I also use lots of random stuff for my models so this can be very helpful. Sulherokhh (Team Chamber Member) - Wednesday November 18, 2009 - 5:39 Yippee! I love tuts like that, easily accessible and immediately useful. |
|||||||||||||||||||||||||||||||||
"One site to rule them all, one site to find them, © All Rights Reserved Eric Edwards ©2013. |