Post
by raidho36 » Mon Mar 02, 2020 1:08 am
A game doesn't need to have pretty source code, it just needs to work.
Metatables are your go-to syntax sugar for calling methods on objects. Doing it the C way is faster but that's C way, so not ideal. What __index does is, basically, hooks up another table to your existing table as a backup. It's marginally slower than just filling in your existing table with all the same values (such as functions) from the index table, but it usually means saving a lot of memory, which may or may not be preferable depending on specific circumstances. Metamethods are usually of no use whatsoever, mainly because you'll struggle to set them up such that they don't generate memory garbage, and you generally don't want to generate any garbage. OOP is a gigantic meme (though absolute majority of people are taking it completely unironically for some unfathomable reason; none of it is uniquely beneficial and a lot of it is actively detrimental), so don't sweat over it. Data-oriented design is what you should aim for, but if you want something more intuitive then you can use "structs with methods" approach, i.e. your "class" is just a dumb data container with a bunch of functions attached to it as appropriate.
You start the project at the whiteboard - as usual. Formalize everything about it, put it into words, numbers and charts. Don't assume your gameplay ideas will be automatically good (or bad) however - instead just quickly throw together a barely functioning program to see how it actually plays.
The most important thing to learn - or rather, internalize - is that programming isn't magic. You don't put down a bunch of random commands and hope that it works. Every instruction has exactly specific meaning, exactly specific consequence. When you write an instruction it's because you intend that consequence to happen, exactly that consequence. This sounds simple and obvious when you spell it out, but it flies over the heads of many beginners and they end up fumbling helplessly over the smallest obstacles because they hope to juggle it around until it's somehow fixed instead of referring to the manual. You don't start being good at programming until you fully grasp this, you don't start building great clockwork machines until you fully understand that ritualistic hand movements will not make a bunch of brass move on its own. Once you get this, it will be a breeze from there, and with any luck you will get this immediately.