1# JSON Loading Order #
2
3All files here in data/json are read eventually, but the order in which they're
4read can be important for objects with dependencies on other kinds of objects
5(e.g. recipes depend on skills). Ensuring the proper loading order will prevent
6surprises that, most often, manifest as crash-to-desktop with segfault (a very
7bad thing).
8
9The way Cataclysm finds and loads json files is by running a breadth-first
10search in the tree data/json/. This means `data/json/whatever.json` will
11**always** be read before `data/json/subdir/whatever.json`. This tells us how to
12ensure dependency loading order.
13
14For instance, if you have scenarios that depend on professions that depend on
15skills, you'll want a directory structure such as the following:
16
17```
18data/json/
19  skills.json
20  professions/
21    professions.json
22    scenarios/
23      scenarios.json
24```
25
26Which results in a loading order of: `skills.json` then `professions.json` and
27then `scenarios.json`.
28
29## Same-depth loading order ##
30
31Note that, when files (or directories) are at the same depth
32(i.e. all in `data/json/`), they will be read in lexical order, which is
33more or less equivalent to alphabetical order for file names that use only
34ascii characters. For UTF-8 or otherwise non-ascii file names, the names will be
35ordered by codepoint.
36