The Lua-MMF2 Combo
Author: | Muz
|
Submitted: | 16th January, 2009
|
Views: | 8885
| Rated: |
|
|
MMF2 has a huge flaw: Scripting. It does anything in 2D wonderfully, but everything that requires text is messy and ugly.
Lua has a huge flaw: Interface. But it's probably one of the best amateur scripting systems out there, because it's incredibly flexible, easy to learn and use, and even lets you get away with sloppy coding.
Put these two together, and you've got the most powerful game-making utility in the world. Used right, Lua can be even more useful to your game than fatloops. Forget C++, the Lua-MMF2 combo can replicate the creation of just about any game made in the 19th century.
As I've been learning Lua, I'm going to write an article on trying to adapt to the system while my mind is still fresh from trying to learn it.
Learning Lua
This is the best website on Lua, easily as good what you'll get from books:
http://lua-users.org/wiki/TutorialDirectory
But do it from the top and actually try to copy it. I tried to skim through it and got confused
Advantages of Lua-MMF2
Because Lua is better suited for scripting, I tend to do all the processing in Lua and all the interface work with MMF2. Lua is the brain; MMF2 is the body.
Lua can easily handle the processing, meaning that if you have a game that uses trigonometry or other math heavily, you're saving a lot of time in the expression editor. It's much easier to write 1000 lines of Lua code than do 50 events with 20 actions each. In fact, because of functions, you won't even need 1000 lines.
Also, Lua is great for data storage because you can easily build your own arrays and load files from INI-like files. You no longer need separate files, especially for moddable games. What's even better is that it could update the stored value automatically. So, if you were had a Damage variable which is directly proportional to Strength, you could update Damage every time Strength changes.
Functions are the beautiful thing. They're as useful as fastloops, but can do much more. Get to know them well.
Getting used to it
The first problem is that you'll actually have two different parts of code to get used to. Imagine having your game in 2 different frames - one which does the game, and the other which does the processing for part of the game.
Just remember that MMF is your end result. Nothing goes into MMF without being a function. Your focus should be what you want to appear in MMF.
Also know that MMF can easily take out most non-array variables directly from Lua, which is good for auto-updating storage. But MMF seems to have some trouble getting array files like Array.Item.Value from Lua. Instead of taking it directly, call something like
function getarray() return Array.Item.Value end
If you want to make things simpler, just use Lua as a calculator instead. Put a function in it for every complicated calculation. Or as an auto-updating data storage thingy.
The most important thing with this is to learn to plan ahead. Just plot out which sections of your code Lua is supposed to do. It makes things a lot easier, trust me.
Things you should remember
Well, here's a few things I spent a few days figuring out. Here's to hoping you don't make the same mistake
- DoCall calls a function into MMF as a condition. It's what you use for making conditions.
- You can also call a Lua function, to make Lua do the work. If you set a return in that function, it will also return a value that you set.
- Lua arrays start with 1, not 0.
- MMF return starts at 0. It's a bit confusing there. Just remember, Lua: 1; MMF: 0.
- True and false are not 0 and 1 in Lua. It's literally true and false.
- Strings are automatically converted to numbers and vice versa when Lua sees fit. Just remember that whenever MMF2 sends something to Lua, it is usually in string form, except when you take a public value, in which it'll convert it into a value.
- If something like Array[text] doesn't work, try Array["text"] instead. Array[text] actually takes the contents of a variable called text.
- To convert a string to number, use tonumber()
Finally, Lua is much more difficult than MMF2, doing both at once is not easy either. It's also not necessary to make a good game, just a way of going beyond what MMF2 can do. If you're still learning to use MMF2, it's much more important to master MMF2 first, before you can pull any tricks with a Lua-MMF2 combo.
But once you do learn both, you could do a lot more, with a lot less effort.
|
|
|