Diving into Scripting....

Hey guys! Long time no chat.

I’m building up my game engine and beginning to design my scripting system. This is more a theory question than anything else, as this will be the first major scripting system I’ve ever written (using Lua with libgdx, for the curious). I basically am going to (tentatively, pending suggestions) have a system that operates as follows for character class behavior:

  1. Classes are defined in individual .lua files loaded at runtime (i.e., bandit.lua, warrior.lua, necromancer.lua, etc.). These define things like what weapons are compatible, the class description, what abilities it learns, etc.
  2. Abilities are defined in their own individual .lua files also loaded at runtime and referenced from the aforementioned class files (i.e., steal.lua will define what actually takes place when a character utilizing a thief class steals, and so forth).

I look at that model and think hm, it seems like it would be a good idea to blend the two together and instead just have one .lua file for each class that encompasses the abilities as well. Though clean, there’s also the part of me that wouldn’t know how to encapsulate those moves properly, as the end goal is to have Lua call something like new Class() with the class script file and new Ability() with each ability so that the classes are generic enough to fully encapsulate themselves and their behavior, and having the class file also contain the logic for each ability would presumably make this difficult unless I incorporate some meta-based object-oriented programming to hold the information for each ability… this comes with the trade-off of readability and simplicity for someone like my partner to be helping with the scripting, who is more design-based than code-based. Also, having the moves separate allows other classes to reuse those same moves.

Typically, I wouldn’t necessarily approach scripting for something like this were my game to have on the order of 10-15 classes, but there are going to be (and don’t laugh) roughly 100 classes at this point, all of which my partner and I have outlined already. Being able to script these rather than hardcode them just makes sense, especially because each class will also have 5-10 abilities that are unique to it (though some may have shared moves as mentioned before, lending utility to the scripting approach).

There are other areas of the engine I intend to script (entity generation, behaviors, questing, weapon and spell effects), but I figured this would be a good place to begin in terms of learning how to do things. I would love hearing suggestions as to how to fine-tune or change this approach to be more optimized or cleaner, and if anyone has insight on how to factor or reapproach the aforementioned issue with separate script types, that would be great as well. Scripting is looking like a very exciting frontier for a dynamic engine, but there are many things to consider, it would seem. Thanks in advance!

Colton