As projects grow, confusion can eventually build up with regards to the number of vars kicking about and it can get quite messy to remember what refers to what. Thought I’d post some recommendations for naming conventions that can make it easier to clearly identify where a vars (or functions) come from within your project.
My personal preference is something like this:
(e.g. CstKtn3Pie could represent Castle -> Kitchen -> Node 3 -> Apple Pie,
or Ktn3Pie could represent Kitchen -> Node 3 -> Apple Pie)
- Try keep abbreviation sections in the var name down to 3 characters each otherwise names can get insanely long (CstKtn3Pie is a lot more manageable than CastleKitchenNode003ApplePie!).
- Ideally, you should be able to look at a var name and recognise exactly where it comes from in your code or guess what it should be called if needed in other parts of the code.
- Also, even though LUA var types don’t need to be declared, it can be helpful to pre-append the var with a single char representing the contents of the var (‘s’ for string, ‘i’ for integer, etc. - e.g. iCstKtn3PieNo might be used to represent the number of pies at node 3 in the castle kitchen).
- Name functions appropriately (e.g. ftnCstKtnLever for a function that operates a secret lever in the castle kitchen). You may not have to state the node in a case where the function could be called from more than one particular node number (e.g. maybe the secret lever could be accessed from two different nodes).
- For globally used vars or functions, you might use ‘Gbl’ instead of the room (e.g. iGblNodRes to represent Global Node Resolution that would hold an integer value of 2048).
Might seem overkill but, as your game project grows in size, it can make navigating and writing code much clearer and prevent you from accidentally reusing an already existing var name.
There are plenty of naming convention standards out there - this is just one that appealed to me that, so far, has worked well the node-based adventures. Does anyone else have other coding styles or tips they recommend?