Skip to content

Coding Guidelines

Marcel de Vries edited this page Jul 12, 2017 · 3 revisions

Documentation

  • Include a NaturalDocs formatted header in your functions

Sanity Checking

  • Use CBA ASSERTS to validate data before progressing
  • Ideally for every function, use ASSERTS to validate input parameters and output results

Functions Naming

  • Use ALIVE_fnc_xxx for your function definitions
  • Always use fnc_xxx.sqf for your function file names

Test Harnesses

  • Integrate Test scripts to automate testing inherent to the development process
  • When bug fixing, modify the test script first to identify the bug, fix the bug, re-run test script
  • CBA_fnc_test for testing frameworks

Object Orientation

  • Use Object Oriented SQF
  • Utilise inheritance/reuse of existing code wherever possible from a parent class using OO

Important Reading

Good Practice

  • Embrace CBA use of Macros
  • Embrace CBA use of function wrappers
  • CBA_fnc_debug/error/log and associated MACROs for debug level messages
  • Avoid execVM/spawn where possible
  • Move all initialisation code/messaging into the module directory
  • Avoid global variables - if you want to share a variable, use setVariable on a server side game logic as this allows for multiple instances of the same module.
  • Wherever possible use stringtable.xml files to facilitate language localisation in future.
  • count is for counting and forEach is traversing items in a collection.

Rules of Thumb

  • Avoid loops!
  • Non critical operations that have a "near" end can be scheduled but critical operations (like animations or things where you need an exact execution) must be handled within one frame.
  • It's better to handle code in unscheduled space because you have direct control over it and it isn't impacted by "engine laziness", as in "waiting" for the next operation to happen.
  • You know that your code is executed non-scheduled if waituntil and sleep _time; (within the code you want to execute) doesn't work and an appropriate error is logged to RPT!
  • If you want to process too much data in one frame or you overload the schedular then the game engine will freeze for a moment, so split the operations over several frames.