Tag Archives: structure

Structure of Lua files

Structure of Lua files

I noticed that a colleague organized his lua code by groups of functionality (i.e., sounds in one section, animations in another) rather than how the functions occur sequentially.  Initially it looked nice and clean but then it became a CTRL-F exercise to go through the rabbit hole of the sequence of the script.

My scripts are generally set up procedurally whereby the topmost items are items that occur first in the scene or level.  For items that can occur simultaneously, I group them in sections.  Functions that are simple or consistently occur in a scene, I put at the bottom and local variable declarations at top.

I’m not sure which method is better, but I think that overall it’s easier to read sequentially especially in situations where the flow or logic is complicated.