User Tools

Site Tools


codex

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
codex [2022/06/17 22:14] justincodex [2022/12/22 18:17] (current) justin
Line 2: Line 2:
 ---- ----
  
-A **codex** is a data type with its data stored as key/value pairs. Each key is a unique [[string]] and acts as a lookup for its corresponding value within the codex, similar to a dictionary. The key/value pairs are enclosed by square brackets after the "codex" keyword, with each key written as a [[string]] and a colon between a key and its corresponding value. Key/value pairs are separated by commas. If loading data from a JSON file and it contains an object with properties, the object will be stored as a codex (see [[Data Files]]). See below for an example.+A **codex** is a data type with its data stored as key/value pairs. Each key is a unique [[string]] and acts as a lookup for its corresponding value within the codex, similar to a dictionary. The key/value pairs are enclosed by square brackets after the "codex" keyword, with each key written as a [[string]] and a colon between a key and its corresponding value. Key/value pairs are separated by commas. If loading data from a JSON file and it contains an object with properties, the object will be stored as a codex (see [[Data Files]]).
  
 ====Example:==== ====Example:====
Line 8: Line 8:
 codex["id": "ITEM_0001", "count": 5] codex["id": "ITEM_0001", "count": 5]
 </code> </code>
-The codex variable will contain a lookup with keys named "id" and "count", with corresponding values of "ITEM_0001" (as a [[string]] value) and 5 (as a [[number]] value). You could create a JSON [[data_files|data file]] containing an [[array]] of these codices as an easy way to maintain a list of [[item|items]] to give to the player when the game starts.+The codex variable above will contain a lookup with keys named "id" and "count", with corresponding values of "ITEM_0001" (as a [[string]] value) and 5 (as a [[number]] value). You could create a JSON [[data_files|data file]] containing an [[array]] of these codices as an easy way to maintain a list of [[item|items]] to give to the player when the game starts.
  
 +====Modifying a Value:====
 +<code bauxite>
 +$my_codex = codex["id": "ITEM_0001", "count": 5];
 +$my_codex["count"] = 10;
 +</code>
 +The script above creates a codex variable containing lookups for an item ID and a numeric count value, then modifies the count to 10.
 +
 +====Inserting a Value:====
 +<code bauxite>
 +$my_codex = codex[];
 +$my_codex["unique_key"] = "Some Value";
 +</code>
 +The script above creates an empty codex variable, then inserts a new key/value pair with a key of "unique_key" and a [[string]] value of "Some Value".
 +
 +~~NOTOC~~
codex.1655529296.txt.gz · Last modified: 2022/06/17 22:14 by justin