Hi,
Yesterday evening (CET) I made a first test with Lua scripting for my
project, H-World. It worked surprisingly well. In less that 1 1/2 hours I
had the lua interpreter integrated and built a first bridge to call Lua
scripts on an event.
My test: If the player 'u'ses an item, a lua function can be executed to
determine what should happen. I have no idea at the moment if this is a
clever thing, but it worked nearly immediately.
Somone suggested to bind scripts to events. I think this is what I'll do.
The game engine generates events like 'use item', 'wield item', 'take off
item' etc. Basically an event for everything the player can do. If an object
is involved in the action (always an item in the above given examples), the
item is inquired for a Lua function name (configured in the item
configuration file, that is a text file like in Angband) and if a function
is bound, this function is then called, the parameter are a handle to the
item and a handle to the user (the player or a monter). Thus most
functionality can be externalized into scripts.
To alter the games data, I'll export the following to the scripts:
world class - to load/generate levels
level class - to access game levels
sqaure class - to access sqaures within a level
thing class - in H-World monsters, items and the player are objects of the
thing class
Maybe more will be neccesary. If somone has an idea if the above are a good
or bad idea to export, please let me know. Only the public part of the
interfaces will be exported - well, ok, without knowing the code you can't
judge if that's good or not.
Combat will be scriptable, too, with events generated before attack, for the
attack and after an attack. There will be default implementations for all
three, but each wepaon (item) or monster can override them and replace them
with something else (another script). That means, special weapons or special
monsters can have completely different scripts for combat than the ordinary
things - I think this will allow some nice effects for special or boss
monsters and special weapons.
H-World will most likely become a game engine and a default game built on
it. The game engine will most likely stay closed source, and the game will
be Lua scripts - 'open source' in that sense that everyone can edit them,
add new scripts or whatever he wants to do with them. I definitely hope that
someone will start to build his own game or variant with it some day, when
H-World is off the ground and the engine is complete. But as of yet this is
far future.
It seems that for a closed source engine, scripting is essential - the
configuration files H-World currently uses allow to define the game world,
but the functionality can't be changed. By using scripts, the functionality
can at least be extended, that should be a great benefit.
Someome said, altering a C file and doing 'make' is fast enough. I agree,
but somehow altering a lua script and just restart the game engine feels
more convenient IMO. There is even the chance to reload altered scripts
while the game is running - i.e. if you test a quest, and you find a
mistake, you can alter the script, reload it (without exiting the main
program) and test the change. I don't know yet if this is a good idea, but
at least it is an option.
Last but not least, scripts have a definite 'coolness factor' :)
Btw, I want to gratulate the Angband maintainers for their choice of Lua.
I've seldom seen a component or subsystem that could be integrated that
smoothly and without problems.
Kind regards,
Hansjörg Malthaner
http://h-world.simugraph.com