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/12/22 18:17] justincodex [2025/03/11 17:18] (current) justin
Line 9: Line 9:
 </code> </code>
 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. 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.
 +
 +====Reading a Value:====
 +<code bauxite>
 +$my_codex = codex["id": "ITEM_0001", "count": 5];
 +display_message("The item's count is " + str($my_codex["count"]));
 +</code>
 +The script above creates a codex variable containing lookups for an item ID and a numeric count value, then displays the count (converted to a [[string]] value) in a message.
  
 ====Modifying a Value:==== ====Modifying a Value:====
Line 23: Line 30:
 </code> </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". 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".
 +
 +====Iterating All Keys:====
 +<code bauxite>
 +$my_codex = codex["name": "Stumpy", "genus": "Sciurus"];
 +for $key in $my_codex do
 +   display_message("Key: " + $key + ", Value: " + str($my_codex[$key]));
 +end;
 +</code>
 +The script above displays each key of the codex along with its corresponding value. The "str" function is used to convert whatever the stored value is to a [[string]] before displaying it.
  
 ~~NOTOC~~ ~~NOTOC~~
codex.1671761837.txt.gz · Last modified: 2022/12/22 18:17 by justin