PDA

View Full Version : Naming conventions and other stuff



Ian
01-02-2007, 02:54 AM
Of course anyone making a game can use their own stylistic conventions in Lua, but were someone to write something that is harmonious with the standard library it would be nice to know what your (Seth's) naming conventions are.

It looks like functions are WrittenLikeThis and everything else (parameters, locals, and so on) is writtenLikeThis, except for internally used constants.

Also, I am writing some methods like Item:OnEquip that returns false if the item cannot be equipped, thus causing Character:Equip to fail. Do you think this right, or should I have a separate function for that? (OnPreEquip, CanEquip, etc.) (OnPostEquip is called after the item is successfully equipped.)

Seth
01-03-2007, 03:46 AM
Here's the naming conventions I'm trying to use:

Function: FunctionName
local variable: someVariable
Script-wide variable (per entity): m_someVariable (each script has its own namespace internally)
Global variable: g_VariableName; (can be read/written by all scripts and all functions)

Lua doesn't seem to support real constants, so I use normal variables but name them like this: C_SOME_CONSTANT.

How you're using OnEquip seems fine to me, I could go either way on that.

Oh, for entity "data" naming, the stuff that is automatically saved and loaded with entities on a per entity level, I think I'm trying to use all lower case. Ie, "this:Data():Set("npc_name", "Some Dude");

For entity naming, I've been trying to use lowercase with underscores too, at least for things like "text_template", so when calling them by name to clone them it will be a little easier to remember.