Script execute vs object inheritence
So I'm venturing out on my largest project in GML to date and have structured my project in a rather unique way to maximise code reuse and simplify creating many "unique" objects.
Before I delve into code structure the questions I have are regarding any potential performance issues. I can't see why there would be but hey I'm sure the more experienced folks will know better :)
(Excuse lack of actual code, virgin media is down so I'm stuck on my phone)
I'm from an OOP background and trying not to use object when I mean OOP object lol
I've opted to use scripts to store base values for GML objects such eg scrBaseWeapon that has various properties eg cost, damage, name etc. Each unique weapon has its own script that calls scrBaseWeapon to populate default values, and a reference (??) To another script to handle special modes (eg scrMachinegun.special = scrHyperBullets) which is called via script_execute when needed.
The same gun also has another script to be called each step (more on that in a moment)
My GML object has an objBaseWeapon with create event set to the aforementioned script. My machine gun object inherits objBaseWeapon and overrides a few details (cost, name) in create and event_inherited (). This works quite well for separation and reuse of code. Whilst keeping GML object creation easy and clean.
Each weapon (GML object) has its own step event that may or may not differ from base so objBaseGun step is usually left as is.
Same with draw event, the option to override is there, but not usually necessary as objBaseWeapon.draw calls scrDrawBaseWeapon to handle animations etc. But if I need a special case I can include separate drawing scripts as needed
My main concern is memory leaks and performance hits as I'm basically trying to write flexible but easily extensible code for various objects in a way I'm not sure GML was designed for. Am I just fighting an uphill battle trying to get GML to behave this way or is it a viable pattern for the language.
I'm working towards loading the values from a database to allow some minor editing and the such.
Much obliged for your help.
Cheers.
Posted Feb 16, 2017, 11:24 PM UTC · edited